Нужна помощь в сопоставлении регулярных выражений, пожалуйста.Я пытаюсь сопоставить строку текста с двойными кавычками внутри большой строки, которая сама может содержать пары двойных кавычек!Вот пример:
"Please can ""you"" match this"
Более полный пример моей проблемы и того, где я до сих пор находился, показан ниже.Приведенный ниже код правильно хранит только 'paris' в хэше, и Лондон, и Мельбурн неверны из-за пары двойных кавычек, рано заканчивающей длинное описание.
Любая помощь очень ценится.
use strict;
use warnings;
use Data::Dumper;
my %hash;
my $delimiter = '/begin CITY';
local $/ = $delimiter;
my $top_of_file = <DATA>;
my $records=0;
while(<DATA>) {
my ($section_body) = m{^(.+)/end CITY}ms;
$section_body =~ s{/\*.*?\*/}{}gs; # Remove any comments in string
$section_body =~ m{ ^\s+(.+?) ## Variable name is never whitespace seperated
## Always underscored. Akin to C variable names
\s+(".*?") ## The long description can itself contain
## pairs of double quotes ""like this""
\s+(.+) ## Everything from here can be split on
## whitespace
\s+$
}msx;
$hash{$records}{name} = $1;
$hash{$records}{description} = $2;
my (@data) = split ' ', $3;
@{ $hash{$records} }{qw/ size currency /} = @data;
++$records;
}
print Dumper(\%hash);
__DATA__
Some header information
/begin CITY
london /* city name */
"This is a ""difficult"" string to regex"
big
Sterling
/end CITY
/begin CITY paris
"This is a simple comment to grab."
big
euro /* the address */
/end CITY
/begin CITY
Melbourne
"Another ""hard"" long description to 'match'."
big
Dollar
/end CITY