in reply to This regex seems to have splattered non-greedy everywhere
Update: By the way, I came up with a way to use split() for this kind of problem -- splitting on a pattern unless you're inside quotes (or the like). It's ugly, and probably not fit for production, but here it is:
Try that on your data. It's sick.while (<DATA>) { chomp; my $q = 0; # documented for the faint of heart my @fields = split m{ ' # if we match a ' (?{ $q = !$q }) # toggle $q (?!) # and fail (don't split here) | # OR XX # if we match XX (?(?{$q}) # and $q is true (?!) # fail (don't split here) ) # otherwise it succeeds and splits }x; print "[", join("][", @fields), "]\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: This regex seems to have splattered non-greedy everywhere
by fizbin (Chaplain) on Aug 10, 2005 at 18:07 UTC | |
by japhy (Canon) on Aug 10, 2005 at 18:15 UTC | |
by fizbin (Chaplain) on Aug 10, 2005 at 20:12 UTC |