Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Printing regular expression variable

by AnomalousMonk (Monsignor)
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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (10)
As of 2014-08-28 03:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (255 votes), past polls