Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Passing a variable to a regex

by Athanasius (Archbishop)
on Sep 17, 2015 at 11:17 UTC ( #1142311=note: print w/replies, xml ) Need Help??


in reply to Passing a variable to a regex

Hello mavericknik,

I see choroba has answered your question, but I wanted to ask: what is [NOR|OR] supposed to do in the regex? It is actually a character class, which matches any one character from the list “N”, “O”, “R”, “|”:

21:10 >perl -wE "my $s = ' NOR42'; $s =~ / [NOR|OR](.*)/; say $1;" OR42 21:10 >

Did you mean to write this: (?:NOR|OR)? If so, it can be shortened to: N?OR.

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Replies are listed 'Best First'.
Re^2: Passing a variable to a regex
by mavericknik (Sexton) on Sep 17, 2015 at 11:37 UTC
    Wow thanks a lot for that! I was just going through the results after fixing the script and getting weird results. Makes sense now!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2023-02-01 18:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer not to run the latest version of Perl because:







    Results (12 votes). Check out past polls.

    Notices?