Possible
Duplicate:
href="https://stackoverflow.com/questions/2301285/what-does-lazy-and-greedy-means-in-regexp">what
does lazy and greedy means in regexp?
I
know that in Regex the question mark after *, + or ? means ungreedy but if I want to
match any character, what is the difference between using (.*) or (.*?)
?
Thanks.
EDIT:
In
my case I want to check a URL. What are the differences
between
http://site\.net/(.*?)\.html
and
http://site\.net/(.*)\.html
?
Answer
Assume that you got this
url:
http://example.net/some/wierd/path.html?returnTo=somedoc.html
Greedy
would match entire
line:
http://example.net/some/wierd/path.html?returnTo=somedoc.html
while
non greedy
returns:
http://example.net/some/wierd/path.html
href="http://refiddle.com/" rel="nofollow noreferrer">http://refiddle.com/
is great for trying out regular expressions
No comments:
Post a Comment