Hena has asked for the wisdom of the Perl Monks concerning the following question:
I'm currently parsing a string with defined format (tag[value]) like this:
Now the value ($2 in code) should be allowed to have regex pattern within it. This causes the obvious problem of have tag like T[[pP]attern]. So i could go through the string one char at a time and calculate openings ([) so that i get the tag and value pairs, but it doens't look like perl (more like c).while (m/(\w{1,2})\[(.+?)\]/g) { push(@{$hash{$1}},$2); }
TIAwhile (m/(\w{1,2})\[(.+?)\](?=(?:\w{1,2}\[)|\z)/g) { push(@{$hash{$1}},$2); }
Edit by tye, escape [
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Regex dynamics
by Fletch (Bishop) on Feb 10, 2004 at 15:35 UTC | |
|
Re: Regex dynamics
by halley (Prior) on Feb 10, 2004 at 15:38 UTC | |
|
Re: Regex dynamics
by ysth (Canon) on Feb 10, 2004 at 15:59 UTC | |
|
Re: Regex dynamics
by broquaint (Abbot) on Feb 10, 2004 at 15:41 UTC | |
|
Re: Regex dynamics
by borisz (Canon) on Feb 10, 2004 at 15:51 UTC | |
by Hena (Friar) on Feb 11, 2004 at 09:16 UTC | |
by borisz (Canon) on Feb 11, 2004 at 09:47 UTC | |
by Hena (Friar) on Feb 11, 2004 at 10:18 UTC | |
by borisz (Canon) on Feb 11, 2004 at 14:09 UTC | |
| |
|
Re: Regex dynamics
by graff (Chancellor) on Feb 11, 2004 at 01:57 UTC |