Today's Question:  What does your personal desk look like?        GIVE A SHOUT

 ALL


  Greedy and Nongreedy Matching in a Regular Expression

By default, pattern matching is greedy, which means that the matcherreturns the longest match possible. For example, applying the patternA.*c to AbcAbcA matches AbcAbc rather than the shorterAbc. To do nongreedy matching, a question mark must be added tothe quantifier. For example, the pattern A.*?c will find theshortest match possible.COPY// Greedy quantifiersString match = find("A.*c", "AbcAbc"); // AbcAbcmatch = find("A.+", "AbcAbc"); // AbcAbc// Nongreedy quantifiersmatch = find("A.*?c", "AbcAbc"); // Abcmatch = find("A.+?", "AbcAbc"); // Abc// Returns the first s...

3,656 0       REGULAR EXPRESSION PATTERN MATCH GREEDY