Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Perl alternation regex looks ok to me?

by toolic (Bishop)
on Sep 18, 2018 at 13:59 UTC ( #1222583=note: print w/replies, xml ) Need Help??


in reply to Perl alternation regex looks ok to me?

Tip #9 from the Basic debugging checklist: YAPE::Regex::Explain

The regular expression: (?-imsx:^.T2|S) matches as follows: NODE EXPLANATION ---------------------------------------------------------------------- (?-imsx: group, but do not capture (case-sensitive) (with ^ and $ matching normally) (with . not matching \n) (matching whitespace and # normally): ---------------------------------------------------------------------- ^ the beginning of the string ---------------------------------------------------------------------- . any character except \n ---------------------------------------------------------------------- T2 'T2' ---------------------------------------------------------------------- | OR ---------------------------------------------------------------------- S 'S' ---------------------------------------------------------------------- ) end of grouping ----------------------------------------------------------------------
You should use parentheses to group the alternation:
/^.T(2|S)/
Or, if there is no need to capture:
/^.T(?:2|S)/

Replies are listed 'Best First'.
Re^2: Perl alternation regex looks ok to me?
by choroba (Archbishop) on Sep 18, 2018 at 14:16 UTC
    Or, if each alternative is one character
    /^.T[2S])/
    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2020-10-20 00:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (208 votes). Check out past polls.

    Notices?