regular expression: perl ==> python

JZ wnebfynj at mnovryyb.pbz
Wed Dec 22 10:14:53 CET 2004


Dnia 21 Dec 2004 21:12:09 -0800, les_ander at yahoo.com napisał(a):

> 1) In perl:
> $line = "The food is under the bar in the barn.";
> if ( $line =~ /foo(.*)bar/ ) { print "got <$1>\n"; }
> 
> in python, I don't know how I can do this?
> How does one capture the $1? (I know it is \1 but it is still not clear
> how I can simply print it.
> thanks

import re
line = "The food is under the bar in the barn."
if re.search(r'foo(.*)bar',line):
  print 'got %s\n' % _.group(1)

--
JZ ICQ:6712522
http://zabiello.om  



More information about the Python-list mailing list