Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re: Printing regular expression variable

by AnomalousMonk (Canon)
on May 27, 2013 at 23:51 UTC ( #1035479=note: print w/ replies, xml ) Need Help??

in reply to Printing regular expression variable

Further to choroba's reply...

... is it safe just to remove the (?^: and the ) and send the middle bit through to the frontend javascript, or does this wrapper actually mean something ...

It actually means something.

Consider the two regexes /^xyz$/ and  /^xyz$/i for case-sensitive versus case-insensitive matching.

>perl -wMstrict -le "my $qr1 = qr/^xyz$/; print $qr1; ;; my $qr2 = qr/^xyz$/i; print $qr2; " (?^:^xyz$) (?^i:^xyz$)

Clearly, the two regexes have very different effects. This difference is lost if you simply strip away the wrapper. The same goes for the other modifiers you could use on a regex.

Take a look at the Extended Patterns section in perlre for the  "(?:pattern)" extended pattern, usually the third one in the section, near the beginning. The flags used may be slightly different in your version of Perl, but this grouping pattern is essentially the 'wrapper' you're talking about.

I don't know enough about Java regexes to be able to advise you about the path forward. Jeffrey Friedl has written the excellent (and expensive) Mastering Regular Expressions that could probably tell you all about this sort of conversion, but beyond that, I'm not sure what to say.

Comment on Re: Printing regular expression variable
Select or Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1035479]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2016-05-28 05:13 GMT
Find Nodes?
    Voting Booth?