in reply to Perl alternation regex looks ok to me?
Tip #9 from the Basic debugging checklist: YAPE::Regex::Explain
You should use parentheses to group the alternation: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 ----------------------------------------------------------------------
Or, if there is no need to capture:/^.T(2|S)/
/^.T(?:2|S)/
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Perl alternation regex looks ok to me?
by choroba (Cardinal) on Sep 18, 2018 at 14:16 UTC |
In Section
Seekers of Perl Wisdom