Welcome to the Monastery | |
PerlMonks |
Re: A (non) reg-ex questionby hv (Prior) |
on Mar 20, 2006 at 14:16 UTC ( [id://537950]=note: print w/replies, xml ) | Need Help?? |
Here's one approach:
That is: a) check that there are no characters that are not 0 or 1, b) check that no 1s precede 0s, c) XOR the string with its reverse - it should give chr(1) for every character. Another approach, this time destructive:
That is: delete "01" from the centre as often as you can, and verify that this deletes all characters from the string. The lookarounds guard against deleting from 101 or 010. And another, using a single recursive regexp:
That is: MATCH := "" | "0" MATCH "1". Update: added missing '/' in s///, per johngg. Hugo
In Section
Seekers of Perl Wisdom
|
|