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