%d not working in re at Python 2.7?

Discussion in 'Python' started by vacu, May 11, 2012.

  1. vacu

    vacu Guest

    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
     
    vacu, May 11, 2012
    #1
    1. Advertising

  2. vacu

    Josh McGee Guest

    %

    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.
     
    Josh McGee, May 12, 2012
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ratman
    Replies:
    0
    Views:
    710
    Ratman
    Sep 14, 2004
  2. Martin Heuckeroth
    Replies:
    5
    Views:
    721
    JiangZemin
    Apr 1, 2005
  3. Alan Silver
    Replies:
    1
    Views:
    3,813
    Alan Silver
    Aug 2, 2005
  4. gaurav tyagi
    Replies:
    14
    Views:
    1,374
    gaurav tyagi
    Jan 20, 2006
  5. Priyanka AGARWAL
    Replies:
    9
    Views:
    10,099
    Gordon Beaton
    May 25, 2004
Loading...

Share This Page