user_78361084
user_78361084

Reputation: 3908

perl to python...how do I?

I am trying to learn python but don't quite understand the syntax. What is the equivalent of:

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

prints:

one
that
here

Upvotes: 4

Views: 142

Answers (1)

user149341
user149341

Reputation:

Try the re module. I think this is equivalent, modulo some of the side-effects on string:

import re
string = "this one this that this here "
for match in re.finditer(r"this\s+(.*?)\s+", string):
    print match.group(1)

Upvotes: 7

Related Questions