I'm having trouble inserting an outside variable into a string using regular expressions.
I have a string which looks like:
string = "7 -"
And I want to insert a integer as a string into the space between the "7" and the "-", and I've tried to use interpolation, like so:
variable = "15"
string = string.gsub(/(\S?\d+)(\s)(\s)(\D)/, '\1\2#{variable}\3\4')
(the \S? is to account for any " - " attached to a digit for whether it is positive or negative)
The output is a string looking like this:
"7 \#{variable} -"
But I want the output to look like this:
"7 15 -"