re.search

James Stroud jstroud at ucla.edu
Mon Mar 6 01:38:55 EST 2006


Rares Vernica wrote:
> Hi,
> 
> Isn't the following code supposed to return ('1994')?
> 
>  >>> re.search('(\d{4})?', '4 1994').groups()
> (None,)
> 
> Thanks,
> Ray

The ? is allowing it to not match before it finds the 1994.

Note:

py> re.search('(\d{4})?', '1994 4').groups()
('1994',)

James

-- 
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/



More information about the Python-list mailing list