in reply to Passing a variable to a regex

Run quotemeta on $val, or use \Q$val\E in the regex.

Update: I also had to add a space to the regex:

s/( [NOR|OR].*.IN1\()(\Q$val\E)( \).*IN2\()([^)]*)(.*)/$1$4$3$2$5/g; # ^
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^2: Passing a variable to a regex
by mavericknik (Sexton) on Sep 17, 2015 at 11:05 UTC
    Thank you, that worked perfectly! Also I appreciate catching the space, I would've lost a lot of time figuring that out. A very small amount of the cases had that space there, I guess I got lucky.