in reply to matching a line with ' and "
You could use a character class and a back reference instead of alternation.
or using perl 5.10my $string = qq{var1='1' var2="2" var3="3"}; while ( $string =~ /(\w+)=(['"])(.*?)\2/g) { print "$1 = $3\n"; }
use 5.010_000; while ( $string =~ /(?<variable>\w+)=(?<delim>['"])(?<value>.*?)\k<del +im>/g) { say "$+{variable} = $+{value}"; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: matching a line with ' and "
by ww (Archbishop) on Jul 18, 2008 at 11:36 UTC |
In Section
Seekers of Perl Wisdom