Construct a SINGLE regular expression that uses only anchoring (^ and $), reptition modifiers (* and +), alternation (|), and grouping ( ( and )) that will determine whether a string consists of only 0's and 1's AND that there are the SAME number of occurrences of the substring '01' as there are '10'.This is a fun exercise, really. Before you start tackling it in the regex sense, though, try to explain how a match works in English (or whatever language you speak).
Examples:
- '101' succeeds, because it has ONE '10' and ONE '01'.
- '1001' succeeds, because it has ONE '10' and ONE '01'.
- '1010' fails, because it has TWO '10's and only ONE '01'.
- '10101' succeeds, because it has TWO '10's and TWO '01's.
In reply to Fun Regex Exercise by japhy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |