-3

What would be a a description in words of the general string that this RE accepts?

(01(10)*11)*

I first thought that it was just any string beginning and ending with 01 and 11 respectively, with any number of alternating 1s and 0s inbetween, but the fact that the entire regex is contained in ()* voids this description.

Cœur
  • 37,241
  • 25
  • 195
  • 267
KOB
  • 4,084
  • 9
  • 44
  • 88
  • 1
    read the explanation box on regex101.com for your regex. It's the most complete explanation you'll get – baao Mar 05 '17 at 22:08

2 Answers2

2

(01(10)*11)*

zero or more repeats of a group composed by:

  • 01
  • zero or more repeats of a group composed by: 10
  • 11

This pattern can match for example:

  • the empty string
  • 0111 => 01##11
  • 011011 => 01#10#11
  • 01101011 => 01#1010#11
  • 0110101011 => 01#101010#11
  • 011011011011 => 01#10#11|01#10#11
  • 011011011011011011 => 01#10#11|01#10#11|01#10#11
  • 011101101101101011 => 01##11|01#10#11|01#1010#11
  • 011010110110110111 => 01#1010#11|01#10#11|01##11
Casimir et Hippolyte
  • 88,009
  • 5
  • 94
  • 125
1
(        # 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 10s, 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.

Regular Jo
  • 5,190
  • 3
  • 25
  • 47