2011-09-19 36 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)