in reply to Re: Regex stored in a scalar
in thread Regex stored in a scalar

A regex should be between / / marks ...

The  =~ operator is sufficiently DWIMic that it will take any string as a regex. It will even take all the  qr// regex modifiers if they are embedded as  (?adlupimsx-imsx) extended patterns.

c:\@Work\Perl>perl -wMstrict -le "my $regex = '(?xms) ((.) \2{2,})'; ;; for my $s (qw(aeiou aeeiou aeiiiou aeioooou)) { print qq{match: captured '$1'} if $s =~ $regex; } " match: captured 'iii' match: captured 'oooo'

... but that won't work ...

The first comment I made is actually rather trivial in the face of your second point; the substitution  s/\),\(/\)\n\(/ is, indeed, a substitution and not a regex — and bang, the whole endeavor hits a brick wall.


Give a man a fish:  <%-{-{-{-<

Replies are listed 'Best First'.
Re^3: Regex stored in a scalar
by Laurent_R (Canon) on Aug 22, 2015 at 16:17 UTC
    Yes, AnomalousMonk, you are right ++, and I actually knew that what I was saying was not quite right, not that I was thinking to you said in your comments, but I was thinking that you can have a regex in the form:
    if (m{pattern}) { # ...
    or many other delimiter pairs. I really wanted to get that point out of the way quickly to get to the real thing about the substitution not being a regex, so that I was a bit negligent in the way I wrote that first part.

    You're absolutely right, the first part of my comment stood for correction.