Perl like regex in Python

Posted by anansi on Stack Overflow See other posts from Stack Overflow or by anansi
Published on 2010-04-14T13:13:14Z Indexed on 2010/04/14 13:23 UTC
Read the original article Hit count: 125

Filed under:
|
|

In Perl I would do something like this for taking different fields in a regexp, separating different fields by () and getting them using $

foreach $line (@lines)
{
 $line =~ m/(.*?):([^-]*)-(.*)/;
  $field_1 = $1
  $field_2 = $2
  $field_3 = $3
}

How could I do something like this in Python?

© Stack Overflow or respective owner

Related posts about python

Related posts about regex