Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

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

by Rhandom (Curate)
on Dec 30, 2015 at 01:59 UTC ( [id://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 (Monk) 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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1151417]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2024-04-19 11:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found