re.search

Fredrik Lundh fredrik at pythonware.com
Mon Mar 6 02:04:13 EST 2006


Rares Vernica wrote:

> Isn't the following code supposed to return ('1994')?
>
>  >>> re.search('(\d{4})?', '4 1994').groups()
> (None,)

it's supposed to return the first thing that matches your pattern, which,
in this case, is the empty string at the beginning of the target string.

if you want to look for groups of four digits, remove the "?"

</F>






More information about the Python-list mailing list