【发布时间】:2023-03-06 05:57:01
【问题描述】:
给定一个带有引号内子字符串的字符串,提取所有这样的子字符串
我已经编写了以下代码,但有些东西告诉我它很丑(尽管它似乎确实可以解决问题)
my $str = 'printf ("hellp;world", and "this is ; also" and )';
loop:
if ($str =~ /"(.*?)"/) {
my $substr = $1;
$str =~ s/"$substr"//;
print "$substr\n";
}
if ($str =~ /"/) {
goto loop;
}
perl quotes.pl
hellp;world
this is ; also
所以它确实按预期工作。
【问题讨论】:
-
子字符串可以转义引号吗?例如。
'printf( "hello \"peter\"", ... )'
标签: string perl extract quotes