in reply to Re: simple perl regex question (or is it?)
in thread simple perl regex question (or is it?)
In this exercise, I don't know in advance whether $1 will match "AND" or "OR", so I do want that value captured, which is why I didn't want to use split.$ perl -le '$str = q{AND (random text) OR (more random text) AND (yet +(more))};print "$1: $2" while ($str =~ /(AND|OR)\s+(.+?)(?=AND|OR|$)/ +g)' AND: (random text) OR: (more random text) AND: (yet (more))
Funny that you should ask about embedded nested ANDs or ORs. The system I'm working on would benefit from this, but I'd have to deal with balanced parentheses and use recursion probably to parse the entire structure. Assuming I could refine to code to do this accurately, I'd probably just end up hung by my own petard...
Many thanks! -Harry
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: simple perl regex question (or is it?)
by AnomalousMonk (Archbishop) on Nov 11, 2013 at 18:30 UTC | |
|
Re^3: simple perl regex question (or is it?)
by Anonymous Monk on Nov 11, 2013 at 07:45 UTC |