-
February 28th, 2008, 10:50 PM
#1
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 =)
-
February 29th, 2008, 11:51 AM
#2
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.
-
March 1st, 2008, 12:21 PM
#3
Re: lazy quantifiers
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 =)
-
March 2nd, 2008, 09:23 PM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|