On Jan 19, Robin Houston said:

>So "foo" is not shrinkable, "bar" is shrinkable and so on.
>Intuitively, a string is shrinkable iff it can be split into
>two pieces $A.$B so that ("$B$A" lt "$A$B"). "bar" is shrinkable
>because you can split it into b,ar and ("arb" lt "bar").
>
>Can you write a regex which matches only shrinkable strings?
>No, you're not allowed to use embedded code constructs ;-)

Embedded code constructs, meaning which?  The (?{ let me see if $X less
than $y }) construct?  Or the (??{ let me craft a dynamic regex instead of
a huge one }) construct?  My solution uses the latter.

  /^((.)\2*)((.).*?\1(??{"[^\Q$4\E-\\377]"})|.*?(??{"[^\Q$2\E-\\377]"}))/

Why did I use (??{ }) here?  Because it compresses a lot of logic into one
dynamic statement.

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
<stu> what does y/// stand for?  <tenderpuss> why, yansliterate of course.

Reply via email to