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)
In reply to Re: simple perl regex question (or is it?)
by LanX
in thread simple perl regex question (or is it?)
by cadphile
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |