0

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?

choroba
  • 231,213
  • 25
  • 204
  • 289
linux
  • 1
  • 1

1 Answers1

-1

Greedy means that it will try to find the longest matching string.

For the following string:

{ this} is a { test} } 

Example of a Greedy regex

\{.*\}

This regex would match the whole following text:

{ this} is a { test} }

Non Greedy

\{.*\}

would match only { this}

Felipe Sulser
  • 1,185
  • 8
  • 19