http://qs1969.pair.com?node_id=1148675


in reply to Re: Check a string for consecutive digits
in thread Check a string for consecutive digits

This another variant that uses qr// to check for the 'or' / '|' of all three digit sequences. I just boil it down to one regex here.

use strict; use warnings; my $dig3_regex_str = join '|', map { ($_, scalar reverse $_) } # 012 and 210 map { join '', $_ .. $_+ 2 } 0..7; # 012, 123, ... my $dig3_regex = qr/$dig3_regex_str/; # Test samples taken from other monks postings ... my @strings = ( '10203040', '1234', '298761', '4562', '856423', 'a12b543c'); for my $string (@strings) { print "Bad string => $string\n" if $string =~ $dig3_regex; }
Ron