in reply to Re: Re: Regexp for alphabetical order match within the string
in thread Regexp for alphabetical order match within the string

OK, here's what perlre(1) says about (??{}):
       ""(??{ code })""
                 WARNING: This extended regular expression fea-
                 ture is considered highly experimental, and may
                 be changed or deleted without notice.  A simpli-
                 fied version of the syntax may be introduced for
                 commonly used idioms.

                 This is a "postponed" regular subexpression.
                 The "code" is evaluated at run time, at the
                 moment this subexpression may match.  The result
                 of evaluation is considered as a regular expres-
                 sion and matched as if it were inserted instead
                 of this construct.

So the RE first matches any character $1, followed by zero or more of any character. Then it evaluates the code in the (??{}). This code evaluates to a character class for a character outside of the range [$1-z]---a character earlier in the alphabet.

If you change the code to print what it's trying, it's clearer what's going on:

if ($ARGV[0] !~ /(.).*(??{print "Searching for [^$1-z] starting at ",p +os($ARGV[0]),"\n"; "[^$1-z]"})/ix)
produces
[sgifford@sglaptop sgifford]$ perl /tmp/t4 abcd Searching for [^a-z] starting at 4 Searching for [^a-z] starting at 3 Searching for [^a-z] starting at 2 Searching for [^a-z] starting at 1 Searching for [^b-z] starting at 4 Searching for [^b-z] starting at 3 Searching for [^b-z] starting at 2 Searching for [^c-z] starting at 4 Searching for [^c-z] starting at 3 Searching for [^d-z] starting at 4 alpha

Other solutions are more efficient, but the OP asked for an RE. :-)

Replies are listed 'Best First'.
Re: Re: Re: Re: Regexp for alphabetical order match within the string
by Nkuvu (Priest) on Oct 30, 2003 at 22:01 UTC
    Thanks for the explanation.