我有一些代码可以抓取文本的“之间”部分;具体来说,是在
然而,问题在于它会卡在第一个“之间”,并且内部字符串位置似乎没有增加。
输入数据是一个带有换行符的文本文件:它们不太相关,但使打印更容易。
foo $someword
和下一个foo $someword
之间。然而,问题在于它会卡在第一个“之间”,并且内部字符串位置似乎没有增加。
输入数据是一个带有换行符的文本文件:它们不太相关,但使打印更容易。
my $component = qr'foo (\w+?)\s*?{';
while($text =~ /$component/sg)
{
push @baz, $1; #grab the $someword
}
my $list = join( "|", @baz);
my $re = qr/$list/; #create a list of $somewords
#Try to grab everything between the foo $somewords;
# or if there's no $foo someword, grab what's left.
while($text=~/($re)(.+?)foo ($re|\z|\Z)/ms)
#if I take out s, it doesn't repeat, but nothing gets grabbed.
{
# print pos($text), "\n"; #this is undef...that's a clue I'm certain.
print $1, ":", $2; #prints the someword and what was grabbed.
print "\n", '-' x 20, "\n";
}