perl to python …我该怎么办?

前端之家收集整理的这篇文章主要介绍了perl to python …我该怎么办?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试学习 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)

猜你在找的Perl相关文章