Results 1 to 2 of 2
  1. #1
    allaudin's Avatar
    allaudin is offline Senior Member
    Join Date
    Apr 2013
    Posts
    271
    Rep Power
    0

    Default Greedy Quantifier

    I have an application that takes a regualr expression and an input string to match with that pattern .For the following input and string
    Enter your regex: .*foo // greedy quantifier
    Enter input string to search: xfooxxxxxxfoo
    It returns :
    I found the text "xfooxxxxxxfoo" starting at index 0 and ending at index 13.
    For this input I have following explaination in tutorial and I know what is Greedy Quantifier:
    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.
    At this point, the overall expression cannot succeed, because the last three letters ("f" "o" "o") have already been consumed.
    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 ???

  2. #2
    allaudin's Avatar
    allaudin is offline Senior Member
    Join Date
    Apr 2013
    Posts
    271
    Rep Power
    0

    Default Re: Greedy Quantifier

    I got it .. I wanted to delete the thread but couldn't find the delete option ..

Similar Threads

  1. greedy algorithm for TSP
    By sara12345 in forum Advanced Java
    Replies: 2
    Last Post: 03-17-2010, 02:40 PM

Posting Permissions

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