Hi All
I'm trying to create a regex to allow me to extract
a value from a string composed of name=value pairs seperated by the '&'
symbol. The problem I have is that there is no guarantee in which order the
name=value pairs will appear - the significance of this being that the final
name value pair in the string is NOT followed by the '&'
symbol.
Example 1
my $teststr =
"VAL1=123&VAL2=456&VAL3=789";
my ($val) = $teststr =~ m/VAL1=(.*?)&/; print $val;
Example 1 correctly prints the value of
'VAL1'
=======
Example 2
my $teststr =
"VAL2=456&VAL3=789&VAL1=123";
my ($val) = $teststr =~ m/VAL1=(.*?)&/; print $val;
Example 2 prints nothing since the 'VAL1=123' name value pair is NOT
followed by a '&' symbol.
=======
Can anyone show me how to construct a regex which will match both cases
i.e. "VAL1=123&" and "VAL1=123"
Thanks in advance for any help
Bill Stennett |
- RE: a regex question Bill Stennett
- RE: a regex question Arthur Cohen
- Re: a regex question Bill Stennett
- Re: a regex question Bill Mosley
- RE: a regex question Catchen, Julian M