perlmeditation
FoxtrotUniform
<p>Monks,</p>
<p>I came across this regex in my compilers course. It
isn't particularly advanced, in terms of Perl's regex
capabilities, but it's complex enough to give pause to most
of the students in this (fourth-year undergraduate) course.
Spend a few minutes figuring out, for instance, the ten
shortest strings that it'll match:</p>
<code>
/^(0|1(01*0)*1)*$/
</code>
<p>Bonus points if you notice a pattern in the set of
strings that it matches....</p>
<p><b>Update:</b> Silly me. In the context of this course,
regexes describe languages, they don't match strings. In
<i>that</i> context, anchors aren't useful. (Finite
Automata match strings, and you can build FAs from regexes
automatically.) But I brought this example over to a Perl
context, and played with the terminology just a bit to make
it friendlier... and slipped up. Anchors added, thanks to
all who pointed it out.</p>
<p><tt>-- <br>
<font color="#000000">F</font>
<font color="#220000">o</font>
<font color="#550000">x</font>
<font color="#880000">t</font>
<font color="#aa0000">r</font>
<font color="#dd0000">o</font>
<font color="#ff0000">t</font>
<font color="#ff0000">U</font>
<font color="#dd0000">n</font>
<font color="#aa0000">i</font>
<font color="#880000">f</font>
<font color="#550000">o</font>
<font color="#220000">r</font>
<font color="#000000">m</font><br>
Found a typo in this node? /msg me<br>
The hell with [paco], vote for [Erudil]!
</tt></p>