Newbie backreference question

George Sakkis gsakkis at rutgers.edu
Thu Jun 30 17:38:48 EDT 2005


> Hi,
> In perl I can do something like:
>
> $a = 'test string';
> $a =~ /test (\w+)/;
> $b = $1;
> print $b . "\n";
>
> and my output would be "string".
>
> How might this snippet be written in python?
>
> Thanks to all...

import re
a = 'test string'
b = re.match(r'test (\w+)', a).group(1)
print b


George




More information about the Python-list mailing list