I have an application that takes a regualr expression and an input string to match with that pattern .For the following input and string
It returns :Quote:
Enter your regex: .*foo // greedy quantifier
Enter input string to search: xfooxxxxxxfoo
For this input I have following explaination in tutorial and I know what is Greedy Quantifier:Quote:
I found the text "xfooxxxxxxfoo" starting at index 0 and ending at index 13.
The first example uses the greedy quantifier .* to find "anything", zero or more times, followed by the letters "f" "o" "o". Because the quantifier is greedy, the .* portion of the expression first eats the entire input string. At this point, the overall expression cannot succeed, because the last three letters ("f" "o" "o") have already been consumed. So the matcher slowly backs off one letter at a time until the rightmost occurrence of "foo" has been regurgitated, at which point the match succeeds and the search ends.
I cannot understand this line what he wants to say, if it is greedy quantifier it will first search the whole string, it shouldn't match the pattern in first attempt as it ends with foo ???Quote:
At this point, the overall expression cannot succeed, because the last three letters ("f" "o" "o") have already been consumed.