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.
|
---|
Replies are listed 'Best First'. | |
---|---|
RE: Fun Regex Exercise
by dchetlin (Friar) on Oct 25, 2000 at 16:31 UTC | |
by tilly (Archbishop) on Oct 26, 2000 at 05:43 UTC | |
by crazyinsomniac (Prior) on Feb 21, 2001 at 08:22 UTC | |
by merlyn (Sage) on Oct 26, 2000 at 07:56 UTC | |
by puck (Scribe) on Oct 26, 2000 at 08:46 UTC | |
by demerphq (Chancellor) on May 18, 2005 at 14:17 UTC | |
by japhy (Canon) on Oct 25, 2000 at 16:44 UTC | |
RE: Fun Regex Exercise
by quidity (Pilgrim) on Oct 25, 2000 at 18:04 UTC | |
by Anonymous Monk on May 16, 2005 at 19:52 UTC | |
by Anonymous Monk on Oct 16, 2010 at 13:53 UTC | |
RE: Fun Regex Exercise
by merlyn (Sage) on Oct 25, 2000 at 17:37 UTC |