in reply to Regexp for alphabetical order match within the string

Just to be different, here's a solution that doesn't use REs or split():

sub isalphabetical { for my $i (0..(length($_[0])-2)) { return 0 if lc(substr($_[0],$i,1)) gt lc(substr($_[0],$i+1,1)); } return 1; }

Replies are listed 'Best First'.
Re: Re: Regexp for alphabetical order match within the string
by aquarium (Curate) on Oct 31, 2003 at 05:46 UTC
    my (off the top of my head) comment is:
    don't use regex...convert each character into ASCI or your "true" alphabetically mapped sequence number (eg. aA->1 etc.) and loop through the string, keeping the highest number seen in a variable. As soon as you hit a lower value, exit the loop and print "not alphabetical". This should beat regexp for longer/complex strings, and you can make your own map of exactly what "alphabetical" is (in Chinese if you like). The solution ends up more portable, flexible (not tied to regex syntax), and runs faster. Sorry, but am about to disembark and go home, so i'll post some code later.