re.match -- not greedy?

Discussion in 'Python' started by EXI-Andrews, Jack, Nov 22, 2006.

  1. >> I wrote:
    >>
    >>>>>> import re;re.match('(a+)(ab)','aaab').groups()
    >>> ('aa', 'ab')
    >>>
    >>> this is the sort of behaviour i'd expect from
    >>> '(a+?)(ab)'
    >>>
    >>> a+ should greedily consume a's at the expense of the string
    >>> not matching

    >
    > Fredrick wrote:
    > that's a misunderstanding of what a regular expression is, though:
    > conceptually, a RE describes a set of strings, and the RE engine is
    > designed to answer the question "does this string belong to this
    > set".


    if that's so, what is the point of +? and *? (?)

    seems to me it's a bit more pragmatic than pure set membership



    jack
    EXI-Andrews, Jack, Nov 22, 2006
    #1
    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. alexk

    greedy match wanted

    alexk, Mar 3, 2005, in forum: Python
    Replies:
    3
    Views:
    348
    alexk
    Mar 4, 2005
  2. EXI-Andrews, Jack

    re.match -- not greedy?

    EXI-Andrews, Jack, Nov 19, 2006, in forum: Python
    Replies:
    6
    Views:
    470
  3. Replies:
    9
    Views:
    374
    Paul McGuire
    Sep 7, 2009
  4. Dan Kelly

    Greedy and non greedy quantifiers

    Dan Kelly, Jan 17, 2008, in forum: Ruby
    Replies:
    4
    Views:
    138
    Robert Klemme
    Jan 19, 2008
  5. Matt Garrish

    greedy v. non-greedy matching

    Matt Garrish, Feb 16, 2004, in forum: Perl Misc
    Replies:
    4
    Views:
    156
    Matt Garrish
    Feb 16, 2004
Loading...

Share This Page