Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: Printing regular expression variable

by AnomalousMonk (Chancellor)
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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1035479]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2018-02-19 06:28 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (258 votes). Check out past polls.