( # opens capture group 1
01 # matches 01, literally
( # opens capture group 2
10 # matches 10, literally
) # closes capture group 2
* # Repeats previous group zero or more times
11 # matches 11, literally
)
* # Repeats previous group zero or more times
Capturing group 2 is only reached when all the other components of capturing group 1 are met. If it can't find 11 after any number of 10
s, it backtracks out and keeps looking.
This would match 01
followed by any number of 10
, including 0/none, followed by `11.
This would match
- nothing, zero repeats of the outer group
- regexes that can match an empty string are useless for
- validation, especially without assertions.
0111 - zero occurrencess of 10
011011 - one occurrence of 10.
01101011 - two occurrences of 10
011101101011 - one occurrence of CG1 where CG2 had no iterations,
- and one where it had 2
- this can and will continue to an infinite number of matches
Please read up on Quantifiers and honestly, you can do a great deal of learning experimenting on regex101. Here's your regex setup there. All the purple dots are because your expression can match empty strings.