in reply to When the only tool you have is a screwdriver...
e =~ u|uae|edefe|ebe|ecIt should be doable in more up-to-date perl. The expression e must start with token u, so let's rewrite it using e => uE?
e =~ u|uauE?|uE?defe|uE?be|uE?cIt should be evident that E? simplifies as
E =~ auE?|E?defe|E?be|E?c
E =~ (au)*(defe|be|c)*
Putting things together:
#! /usr/bin/perl my $g3 = "( d(?1)f(?1) | b(?1) | c )"; # (defe|be|c) my $g2 = "( (?:au)* (?3)* )"; # E? my $g1 = "( u | uau(?2) | u(?2)(?3) )"; # e my $re = qr/ $g1 (?(DEFINE) $g2 $g3 ) /x; warn "$re\n"; /^$re$/ and print while <>;
But of course, this won't work with perl5.6 ...
Update. It looks this simplifies to just
my $re = qr/(u(?:au)*(?:d(?-1)f(?-1)|b(?-1)|c)*)/;
|
|---|