Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > %d not working in re at Python 2.7?

Reply
Thread Tools

%d not working in re at Python 2.7?

 
 
vacu
Guest
Posts: n/a
 
      05-11-2012
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?

Thanks a head
Vacu
 
Reply With Quote
 
 
 
 
Josh McGee
Guest
Posts: n/a
 
      05-12-2012
%

On Friday, May 11, 2012 11:58:01 AM UTC-7, 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'
>
>
> 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?
>
> Thanks a head
> Vacu


%d and %s and such are format strings, not regex.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
response.redirect is not working but server.transfer is working gaurav tyagi ASP .Net 14 01-20-2006 04:22 AM
wifi not working on new hp, or not working after live update =?Utf-8?B?RHJhZ29ueA==?= Wireless Networking 1 10-01-2005 11:17 PM
ASP.NET client-side validation working, but button click not working Alan Silver ASP .Net 1 08-02-2005 03:50 PM
Cookies working on intranet but NOT working on Internet Martin Heuckeroth ASP .Net 5 04-01-2005 01:37 AM
Regular Expression validators NOT working, Required Field validators ARE working Ratman ASP .Net 0 09-14-2004 09:36 PM



Advertisments