in reply to simple perl regex question (or is it?)
something like /(.*?)(AND|OR|$)/g
if you really need the preceding AND|OR do a positive look ahead
/(AND|OR)(.+?)(?=AND|OR|$)/g
sorry can't test ATM.
(Hopefully you don't expect this to work with nested ANDs and ORs within the parens?)
looks good for me HTH
DB<100> $str = q!AND (random text) AND (more random text) AND (yet m +ore)!; => "AND (random text) AND (more random text) AND (yet more)" DB<101> print "$1: $2\n" while $str =~ /(AND|OR)(.+?)(?=AND|OR|$)/g AND: (random text) AND: (more random text) AND: (yet more)
if you can deal with leading empty strings try split
DB<103> @matches = split /(AND|OR)/,$str => ( "", "AND", " (random text) ", "AND", " (more random text) ", "AND", " (yet more)", )
Cheers Rolf
( addicted to the Perl Programming Language)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: simple perl regex question (or is it?)
by cadphile (Beadle) on Nov 11, 2013 at 01:41 UTC | |
by AnomalousMonk (Archbishop) on Nov 11, 2013 at 18:30 UTC | |
by Anonymous Monk on Nov 11, 2013 at 07:45 UTC |