%d not working in re at Python 2.7?

Tim Roberts timr at probo.com
Wed May 16 01:32:47 EDT 2012


vacu <vacu001 at gmail.com> wrote:
>
>I am frustrated to see %d not working in my Python 2.7 re.search, like
>this example:
>
>>>> (re.search('%d', "asdfdsf78asdfdf")).group(0)
>Traceback (most recent call last):
>  File "<stdin>", line 1, in <module>
>AttributeError: 'NoneType' object has no attribute 'group'
>
>\d works fine:
>
>>>> (re.search('\d+', "asdfdsf78asdfdf")).group(0)
>'78'
>
>And google search ignores % in their search, so I failed to find
>answer from Python mailing list or web,
>Do you have any idea what's problem here?

Yes.  %d has never worked.  \d+ is the right answer.  It's just that
simple.  Where did you read that %d should work?
-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.



More information about the Python-list mailing list