CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2007
    Posts
    28

    lazy quantifiers

    hey everyone.. can someone please answer this question for me and provide me with some examples if possible.. i am new to all of this sso just trying to learn.

    I have this statement:

    The regular expression closure operators * and + are also known as quantifiers. Many current regular expression packages in languages like Perl and Java distinguish between greedy quantifiers (denoted by * and +) which match the maximum number of their operand in order to match what follows the quantifier and lazy quantifiers (denoted by *? and +?) which match the minimum number of matches for their operand in order to match what follows the quantifier.

    Can someone please provide me with a practical example which illustrates the need for lazy quantifiers.


    thank you =)

  2. #2
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: lazy quantifiers

    For performance maybe.
    When you write the regular expression "ab.+" (without the quotes obviously), you want to find a string that starts with a followed by 1 or more b's.
    If you run this query on "wwwabbbbbcc", in lazy mode, it can stop parsing after the first b because then you have an a followed by 1 b which matches the query. However, in greedy mode, the parser has to parse all the way up to the character c.
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  3. #3
    Join Date
    Aug 2007
    Posts
    28

    Re: lazy quantifiers

    Quote Originally Posted by Marc G
    For performance maybe.
    When you write the regular expression "ab.+" (without the quotes obviously), you want to find a string that starts with a followed by 1 or more b's.
    If you run this query on "wwwabbbbbcc", in lazy mode, it can stop parsing after the first b because then you have an a followed by 1 b which matches the query. However, in greedy mode, the parser has to parse all the way up to the character c.


    Thank you Marc =)

  4. #4
    Join Date
    Oct 2002
    Location
    Singapore
    Posts
    3,128

    Re: lazy quantifiers

    This is an excellent tutorial for regex.
    http://www.regular-expressions.info/
    quoted from C++ Coding Standards:

    KISS (Keep It Simple Software):
    Correct is better than fast. Simple is better than complex. Clear is better than cute. Safe is better than insecure.

    Avoid magic number:
    Programming isn't magic, so don't incant it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured