我正在尝试学习python,但不太了解语法.相当于:
my $string='this one this that this here ';
while($string=~/this\s+(.*?)\s+/g){
print $1."\n";
}
Run Code Online (Sandbox Code Playgroud)
打印:
one
that
here
Run Code Online (Sandbox Code Playgroud)
试试这个re模块.我认为这是等效的,模拟了一些副作用string:
import re
string = "this one this that this here "
for match in re.finditer(r"this\s+(.*?)\s+", string):
print match.group(1)
Run Code Online (Sandbox Code Playgroud)