http://qs321.pair.com?node_id=1229825


in reply to Re: regex compilation
in thread regex compilation

The output is above in the end block.

What I need is string that behaves just as the compiled regex as I want to feed that into a perl5-compatible regex-engine for go.

Replies are listed 'Best First'.
Re^3: regex compilation
by haukex (Archbishop) on Feb 12, 2019 at 18:12 UTC
    Have you printed the two values you get?
    The output is above in the end block.

    I'm pretty sure that by "the two values", Corion meant $regex1 and $regex2.

    By the way, the only quoting construct that doesn't interpolate at all is here docs with a single-quoted delimiter:

    chomp( my $regex2 = <<'ENDREGEX' ); (?:(?|(?:\")([^\\\"]*(?:\\.[^\\\"]*)*)(?:\"))) ENDREGEX print $regex2, "\n"; my ($match2) = q|"hubba \"bubba\""| =~ /$regex2/; print $match2, "\n"; __END__ (?:(?|(?:\")([^\\\"]*(?:\\.[^\\\"]*)*)(?:\"))) hubba \"bubba\"
Re^3: regex compilation
by AnomalousMonk (Archbishop) on Feb 12, 2019 at 18:25 UTC
    ... string that behaves just as the compiled regex ...

    That's what  qr// is for; see perlop. The  Regexp object returned by qr// is almost a string; it interpolates as a string in  m// s/// qr// expressions or when print-ed or string interpolated. It is not, however, the same as what is produced by the  qq// q// operators.


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