Jessarah FL has asked for the wisdom of the Perl Monks concerning the following question:
What would be the correct regex to print "valid y"my $str='"fld":{xz.,"val":"x"},"fldA":{afd;ladf,"val":"valid y"},"fldB +":{adsa;afda,"val":"invalid val x"}...'; my $fldNm="fldA"; if ( $str =~ /"$fldNm".*"val":"([^"]+)"/ ) { print "\n Val = $1 \n"; }
The current regex matches "fldA" but then skips its actual val and instead gives me the last val value.
Thanks, Jess
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Regex non-greedy match
by toolic (Bishop) on Oct 11, 2013 at 13:06 UTC | |
by Jessarah FL (Novice) on Oct 11, 2013 at 13:13 UTC | |
|
Re: Regex non-greedy match
by ww (Archbishop) on Oct 11, 2013 at 13:22 UTC | |
|
Re: Regex non-greedy match (JSON)
by Anonymous Monk on Oct 11, 2013 at 13:07 UTC |