On 05/11/12 13:58, vacu 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' > > Do you have any idea what's problem here?
Because the regexp module doesn't support using "%d" in this way? I'd be curious is you can point to Python documentation to the contrary. You know what the problem is, you didn't spell it r"\d+" so I'm not sure why you're asking. I've tested as far back as Python2.3 and "%d" hasn't worked like you seem to expect it to in any of those versions. As an aside, use raw strings (as in r"\d+" with the leading "r") instead of regular strings to ensure escaping applies as you expect it to. -tkc -- http://mail.python.org/mailman/listinfo/python-list