flaviusm has asked for the wisdom of the Perl Monks concerning the following question:
data line: "one=1,two=2,three=3,four=4,five=5"
result: $1==1; $2==2; $3==3; $4==4; $5==5
or
data line: "one=1,three=3,five=5"
result: $1==1; $2==''; $3==3; $4==''; $5==5
This is the code I have:
my $string1 = "one=1,two=2,three=3,four=4,five=5"; my $string2 = "one=1,three=3,five=5"; $string1 =~ m/ (?:one=(.*?),)? .* (?:two=(.*?),)? .* (?:three=(.*?),)? .* (?:four=(.*?),)? .* (?:five=(.*?),)? /x; print "one: $1, two: $2, three: $3, four: $4, five: $5\n";
The above code doesn't work as expected neither for string1 nor for string2. I would appreciate your feedback and ideas.
Thank you.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Regular expressions - match
by eff_i_g (Curate) on Jan 24, 2011 at 22:31 UTC | |
|
Re: Regular expressions - match
by jethro (Monsignor) on Jan 24, 2011 at 22:34 UTC | |
|
Re: Regular expressions - match
by wind (Priest) on Jan 24, 2011 at 23:33 UTC | |
|
Re: Regular expressions - match
by flaviusm (Acolyte) on Jan 24, 2011 at 23:05 UTC | |
|
Re: Regular expressions - match
by shree (Acolyte) on Jan 25, 2011 at 06:39 UTC |