Saturday, May 25, 2019

regex - Regular Expressions ungreedy in bash

Choose which of the following strings match regular expression




(1 U 22)*2*

a. 22112222112211
b. 11112
c. The empty string.
d. 12121
e. 1121111222


I did a few search, U means " Ungreedy. Makes the quantifiers *+?{} consume only those characters absolutely necessary to form a match, leaving the remaining ones available for the next part of the pattern. When the "U" option is not in effect, an individual quantifier can be made non-greedy by following it with a question mark. Conversely, when "U" is in effect, the question mark makes an individual quantifier greedy. " https://www.cheatography.com/davechild/cheat-sheets/regular-expressions/




but I totally don't understand it, what does greedy regular expression and ungreedy regular expression mean? and can you show the example that I listed above?

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...