Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Executing a "/foo/flags" regex from a string

by Rhandom (Curate)
on Dec 30, 2015 at 01:59 UTC ( #1151417=note: print w/replies, xml ) Need Help??


in reply to Executing a "/foo/flags" regex from a string

Here is a small snippet that should do what you were asking for (more or less):

perl -E 'my $str = "/regex/i"; my ($pat, $flags) = $str =~ m{^/(.+)/([imsx]*)\z} ? ($1, $2) : die "Bad regex"; my $qr = qr/(?$flags:$pat)/; say qq{Matched "$_" with $qr} for grep {$_ =~ $qr} qw(foo bar baz reGex)' Matched "reGex" with (?^u:(?i:regex))


my @a=qw(random brilliant braindead); print $a[rand(@a)];

Replies are listed 'Best First'.
Re^2: Executing a "/foo/flags" regex from a string
by Radiola (Scribe) on Dec 30, 2015 at 18:05 UTC

    Ah, OK. I guess there's nothing more to the syntax of /regex/flags than, uh, the regex and the flags, so you don't risk losing anything by parcelling them out and putting them back together like that.

    Thanks!

    - Aaron

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2020-09-28 15:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If at first I donít succeed, I Ö










    Results (144 votes). Check out past polls.

    Notices?