RegexCheatSheet.pm: Locking down regex for simple character matches & added tests
parent
d5765807c0
commit
cff1d64eda
|
@ -172,7 +172,7 @@ handle remainder => sub {
|
|||
my $syntax_key = $_;
|
||||
|
||||
# Let the user provide [a-e], [1-2], nice simple examples only!
|
||||
if ($_ =~ /\[([a-zA-Z0-9])\-([a-zA-Z0-9])\]/) {
|
||||
if ($_ =~ /^\[([a-zA-Z0-9])\-([a-zA-Z0-9])\]$/) {
|
||||
return unless are_valid_char_classes($1, $2);
|
||||
#if there are < 3 between them then output all between them, otherwise "0 or 1 .. or 9" style
|
||||
my $range_string = "";
|
||||
|
|
|
@ -38,10 +38,26 @@ ddg_goodie_test(
|
|||
'[M-Y] - Single character range (M or N ... or Y)',
|
||||
html => '<code> [M-Y] </code> - Single character range (M or N ... or Y)'
|
||||
),
|
||||
'regex [3-5]' => test_zci(
|
||||
'[3-5] - Single character range (3 or 4 or 5)',
|
||||
html => '<code> [3-5] </code> - Single character range (3 or 4 or 5)'
|
||||
),
|
||||
'regex [1-2]' => test_zci(
|
||||
'[1-2] - Single character range (1 or 2)',
|
||||
html => '<code> [1-2] </code> - Single character range (1 or 2)'
|
||||
),
|
||||
'regex [b-X]' => undef,
|
||||
'regex [a-Z]' => undef,
|
||||
'regex [Y-E]' => undef,
|
||||
'regex [A-a]' => undef,
|
||||
'regex [z-a]' => undef,
|
||||
'regex [a-1]' => undef,
|
||||
'regex [1-a]' => undef,
|
||||
'regex [1-1]' => undef,
|
||||
'regex [3-2]' => undef,
|
||||
'regex [a-]' => undef,
|
||||
'regex [4-8] fo sho!' => undef,
|
||||
'regex foop [1-3]' => undef,
|
||||
);
|
||||
|
||||
done_testing;
|
Loading…
Reference in New Issue