in reply to Matching patterns with or

Another way:

c:\@Work\Perl\monks>perl -wMstrict -le "$_ = 'The <A} test {B> sentence <C} foo {42} bar {D> baz' +; ;; while (m{ \G .*? ({\d+} | {\w+> | <\w+}) }xmsg) { printf qq{'$1' }; } " '<A}' '{B>' '<C}' '{42}' '{D>'

Update 1: Changed example code slightly so that the test sentence includes all sub-patterns.

Update 2: On second thought, the  \G .*? part of this regex contributes nothing in this particular application; leaving it out does not change the behavior of the match. As Eily wrote, the  /(A|B|C)/g pattern is all you need.


Give a man a fish:  <%-{-{-{-<