Writing your own regex library can help you understand some of the more
obscure features of Perl's regexes. :-)
The following regex matches lines consisting of words whose length form the fibonacci sequence 1, 1, 2, 3, 5, 8, 13, etc. Caveat: All words must consist of the same character.
The following regex matches lines consisting of words whose length form the fibonacci sequence 1, 1, 2, 3, 5, 8, 13, etc. Caveat: All words must consist of the same character.
Examples of valid input:
v
x x xx xxx xxxxx
Ok, it's probably not very useful, but I thought I'd post it anyway.
#!/usr/local/bin/perl use warnings; use strict; while (<>) { print "fibo\n" if /^\s*(?:((?(1)(?(3)(?(2)\2|\3)(\1)|(\S))|\S))\s+ +)+\z/; }
Back to
Cool Uses for Perl