Another way, and configurable, but uses Perl 5.10 regex extensions:
Extended Patterns used are (?(condition)yes-pattern|no-pattern) and (*FAIL) (see Special Backtracking Control Verbs).c:\@Work\Perl\monks>perl -wMstrict -le "use 5.010; ;; my $too_many_consec = qr{ (?(?{ index('0123456789', $^N) < 0 && index('9876543210', $^N) < 0 +}) (*FAIL)) }xms; ;; my $min = 4; for my $s (qw( 123 321 2123 2321 1232 3212 21232 23212 1234 4321 21234 34321 12343 43212 212343 343212 12345 54321 212345 454321 123454 543212 2123454 4543212 )) { printf qq{'$s' -> }; print $s =~ m{ (\d{$min,10}) $too_many_consec }xms ? qq{too many consec: '$1'} : 'consec free' ; } " '123' -> consec free '321' -> consec free '2123' -> consec free '2321' -> consec free '1232' -> consec free '3212' -> consec free '21232' -> consec free '23212' -> consec free '1234' -> too many consec: '1234' '4321' -> too many consec: '4321' '21234' -> too many consec: '1234' '34321' -> too many consec: '4321' '12343' -> too many consec: '1234' '43212' -> too many consec: '4321' '212343' -> too many consec: '1234' '343212' -> too many consec: '4321' '12345' -> too many consec: '12345' '54321' -> too many consec: '54321' '212345' -> too many consec: '12345' '454321' -> too many consec: '54321' '123454' -> too many consec: '12345' '543212' -> too many consec: '54321' '2123454' -> too many consec: '12345' '4543212' -> too many consec: '54321'
Updates:
Give a man a fish: <%-{-{-{-<
In reply to Re: Check a string for consecutive digits
by AnomalousMonk
in thread Check a string for consecutive digits
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |