I'm trying to clean up a file using JavaScript. The file contains lines of text like this:
a <- b + c / d;
I want to replace all <- with = when there is a string of non-whitespace on either side of the <-, separated by a single space. Pretty easy in theory:
line = "a <- b + c / d"
result = line.replace( /(\S+) <- (\S+)/, /$1 = $2/ )
The above code produces /a = b/ + c / d when run. However, conceptually, it should produce a = b + c / d. How can I use $1-style backreferences without allowing JavaScript the opportunity to insert slashes willy-nilly?