有没有办法只将匹配的字符串打印到匹配项?
use strict;
use warnings;
my $match_re = qr/\QCopyright (c) \E( \d .* ) \Q by Bill Shakespeare.\E/xi;
my $str = 'Copyright (c) 2008,2009-2011 by Wordsworth';
if ($str =~ $match_re) {
print "\ncomplete match\n";
} else {
print "\npartial match: \n";
}
在此示例中,我想打印partial match: Copyright (c) 2008,2009-2011 by
,因为它与此匹配。
答案 0 :(得分:0)
假设以
开头的标准BibTeX处理条目(bbl)$string ='\bibitem{bibtex_key} rest';
您可以使用以下行提取这两部分:
my ($bibtex_key, $rest) = $string =~ m/\\bibitem\{(.*)\}(.*)/;
现在您可以轻松地根据您的需求进行调整:)