[Israel.pm] Regex question: alternation between a delimiter and EOL
Gaal Yahas
gaal at forum2.org
Wed Jan 24 14:24:20 EET 2007
On Wed, Jan 24, 2007 at 02:14:00PM +0200, Yossi Itzkovich wrote:
> Hi
>
> I have a line like:
> key=value;key=value;key=value
>
> Each fields ends with ";" except the last one in each line. value can
> not contain ";"
> How can I catch the pair of key=value ?
> I can't do something like:
> /key=(.+?)(;|$)/
> although I'd like too...
Possibly easier not to use a regexp here.
@vals = map { s/key=// or die "bad input: $_"; $_ } split /;/, $string;
But you can also do this:
@vals = $string =~ /key=([^;]+);?/g;
--
Gaal Yahas <gaal at forum2.org>
http://gaal.livejournal.com/
More information about the Perl
mailing list