Possibly related: Parse structured string to dictionary - General Usage - JuliaLang
A simple
_, x, _, y = split("test var_1 and var_2")
sets x and y as desired.
It was not clear from your description if variable names x and y are hard-wired or to be parsed first.
But using $x
in a string does interpolation and requires x to be known.