Thanks Tim, it is my mis-understanding of usage of %d in Python. After reading it carefully, it should be used in re.scan.<div>The reason I made this dump mistake is because I got a script from our expert and I am totally new on Python, before reading your</div>
<div>email, I hadn't a doubt it is wrong usage and didn't examine document carefully. I apologize for you time spent on it. -Vacu</div><div><br><div class="gmail_quote">On Mon, May 14, 2012 at 4:20 PM, Tim Chase <span dir="ltr"><<a href="mailto:python.list@tim.thechases.com" target="_blank">python.list@tim.thechases.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 05/11/12 13:58, vacu wrote:<br>
> I am frustrated to see %d not working in my Python 2.7 re.search, like<br>
> this example:<br>
><br>
>>>> (re.search('%d', "asdfdsf78asdfdf")).group(0)<br>
> Traceback (most recent call last):<br>
> File "<stdin>", line 1, in <module><br>
> AttributeError: 'NoneType' object has no attribute 'group'<br>
><br>
><br>
> \d works fine:<br>
><br>
>>>> (re.search('\d+', "asdfdsf78asdfdf")).group(0)<br>
> '78'<br>
><br>
> Do you have any idea what's problem here?<br>
<br>
Because the regexp module doesn't support using "%d" in this way?<br>
I'd be curious is you can point to Python documentation to the contrary.<br>
<br>
You know what the problem is, you didn't spell it r"\d+" so I'm not<br>
sure why you're asking. I've tested as far back as Python2.3 and<br>
"%d" hasn't worked like you seem to expect it to in any of those<br>
versions.<br>
<br>
As an aside, use raw strings (as in r"\d+" with the leading "r")<br>
instead of regular strings to ensure escaping applies as you expect<br>
it to.<br>
<br>
-tkc<br>
<br>
<br>
</blockquote></div><br></div>