2011-09-19 52 views
4

我想学习python,但不太明白语法。什么是等价的:perl to python ...我怎么样?

my $string='this one this that this here '; 
while($string=~/this\s+(.*?)\s+/g){ 
    print $1."\n"; 
} 

打印:

one 
that 
here 
+0

这实际上很有趣。 –

+4

@MK。请解释这些骗子。 – agf

+0

我发现Perl和“我不懂Python语法”有趣的组合。希望我没有伤害任何人的感情。 –

回答

7

尝试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)