Exact match with regular expression

Discussion in 'Python' started by Mr.SpOOn, Oct 26, 2008.

  1. Mr.SpOOn

    Mr.SpOOn Guest

    Hi,
    I'd like to use regular expressions to parse a string and accept only
    valid strings. What I mean is the possibility to check if the whole
    string matches the regex.

    So if I have:

    >>> p = re.compile('a*b*')


    I can match this: 'aaaaaabbb'

    >>> m = p.match('aaaaaabbb')
    >>> m.group()

    'aaaaaabbb'

    But I'd like to get None with this: 'aabDDDDb'
    Instead it matches the first part:

    >>> m = p.match('aabDDDDb')
    >>> m.group()

    'aab'

    I know this is the expected behaviour, but I'm sure it should be
    possible doing what I said.
    Are there other methods I don't know about in the re module?

    Thanks.
     
    Mr.SpOOn, Oct 26, 2008
    #1
    1. Advertising

  2. Lawrence D'Oliveiro, Nov 1, 2008
    #2
    1. Advertising

  3. On Fri, Oct 31, 2008 at 8:57 PM, Lawrence D'Oliveiro
    <_zealand> wrote:
    > In message <Xns9B43B11B2906ArtwfreenetREMOVEcouk@216.196.109.145>, Rob
    > Williscroft wrote:
    >
    >> Read (and bookmark) this:
    >>
    >> http://www.python.org/doc/2.5.2/lib/re-syntax.html

    >
    > Funny how you never get a thank-you when you tell people to RTFM.
    > --
    > http://mail.python.org/mailman/listinfo/python-list
    >



    Hmmm. Kind of odd. Someone involved in the language they're having
    trouble with wrote some documentation for the exact thing they're
    asking for, you tell them where it is, and that doesn't deserve
    thanks?

    Something's wrong here. Well, it's about time for that which must be
    read by everyone on the Internet to be mentioned again.

    If you haven't read this yet, read this:
    http://www.catb.org/~esr/faqs/smart-questions.html

    Especially if you have asked for help and not gotten what you wanted.
    Especially if people ignore your questions.
    Especially if people give answers that don't help you.
     
    Shawn Milochik, Nov 1, 2008
    #3
  4. Mr.SpOOn

    Mr.SpOOn Guest

    On Sat, Nov 1, 2008 at 1:57 AM, Lawrence D'Oliveiro
    <_zealand> wrote:
    > In message <Xns9B43B11B2906ArtwfreenetREMOVEcouk@216.196.109.145>, Rob
    > Williscroft wrote:
    >
    >> Read (and bookmark) this:
    >>
    >> http://www.python.org/doc/2.5.2/lib/re-syntax.html

    >
    > Funny how you never get a thank-you when you tell people to RTFM.


    My fault :\
    I said "thank you" to Rob, but I just sent a private message. It's
    just that I did a reply and not reply to all.

    Anyway, I RTFM and solved my problem :)

    Thanks again,
    Bye
     
    Mr.SpOOn, Nov 3, 2008
    #4
  5. In message <>, Mr.SpOOn
    wrote:

    > On Sat, Nov 1, 2008 at 1:57 AM, Lawrence D'Oliveiro
    > <_zealand> wrote:
    >
    >> Funny how you never get a thank-you when you tell people to RTFM.

    >
    > My fault :\
    > I said "thank you" to Rob, but I just sent a private message. It's
    > just that I did a reply and not reply to all.


    That's OK. My fault for not realizing. :)
     
    Lawrence D'Oliveiro, Nov 4, 2008
    #5
    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. VSK
    Replies:
    2
    Views:
    2,350
  2. Andy
    Replies:
    2
    Views:
    321
    John Harrison
    Sep 10, 2005
  3. Wayne Shu
    Replies:
    2
    Views:
    282
    James Kanze
    Jul 29, 2007
  4. Neelesh Bodas

    Exact Match and Identity conversion

    Neelesh Bodas, Aug 8, 2007, in forum: C++
    Replies:
    17
    Views:
    733
  5. jimgardener

    finding an exact match of filenames

    jimgardener, Oct 16, 2010, in forum: Python
    Replies:
    1
    Views:
    286
    Peter Otten
    Oct 16, 2010
Loading...

Share This Page