in reply to Use global flag when declaring regular expressions with qr?

For the flags like /g that affect the operator, not the regular expression, you need to just interpolate the re:
if ($row =~ /$re/gc) {
(Internally, I believe this is able to just use the regular expression without having to recompile it.)

You want the /c flag to not reset the match position on failure.

--
A math joke: r = | |csc(θ)|+|sec(θ)| |-| |csc(θ)|-|sec(θ)| |

Replies are listed 'Best First'.
Re^2: Use global flag when declaring regular expressions with qr?
by ikegami (Patriarch) on Oct 28, 2024 at 15:43 UTC

    Good job catching that if ( $row =~ /$re/g ) doesn't make sense. But the solution to finding all matches is replacing the if with a while, not adding "c".

      Oh, right. Not sure what I was thinking.
      --
      A math joke: r = | |csc(θ)|+|sec(θ)| |-| |csc(θ)|-|sec(θ)| |