RegexCheatSheet: Normalising the whitespace around the regex symbols

master
Rob Emery 2014-06-26 21:47:47 +01:00
parent 9de10e2cf0
commit 444ab4a2f4
2 changed files with 12 additions and 12 deletions

View File

@ -209,7 +209,7 @@ handle remainder => sub {
$range_string = join(" or ", ($1..$2)[0,1]) . " ... or $2";
}
return answer => "$_ - Single character range ($range_string)",
html => "<code> $_ </code> - Single character range ($range_string)",
html => "<code>$_</code> - Single character range ($range_string)",
heading => $heading;
}
# Let the user provide a number for the {n} pattern, e.g., {5} would say "Exactly 5 occurrences".
@ -227,14 +227,14 @@ handle remainder => sub {
heading => $heading;
}
return answer => "$_ - $1 or more",
html => "<code> " . encode_entities($_) . " </code> - $1 or more occurrences",
html => "<code>" . encode_entities($_) . "</code> - $1 or more occurrences",
heading => $heading;
}
# Check our map if it's in our list of regex patterns.
return unless $syntax_map{$syntax_key};
my $text_output = "$_ - $syntax_map{$syntax_key}";
my $html_output = "<code> " . encode_entities($_) . " </code> - " . encode_entities($syntax_map{$syntax_key});
my $html_output = "<code>" . encode_entities($_) . "</code> - " . encode_entities($syntax_map{$syntax_key});
return answer => $text_output, html => $html_output, heading => $heading;
}
@ -277,4 +277,4 @@ handle remainder => sub {
return answer => $text_output, html => append_css($html_output), heading => $heading;
};
1;
1;

View File

@ -21,37 +21,37 @@ ddg_goodie_test(
),
'regex ^' => test_zci(
"^ - Start of string or line",
html => "<code> ^ </code> - Start of string or line",
html => "<code>^</code> - Start of string or line",
heading => 'Regex Cheat Sheet',
),
'regex $' => test_zci(
'$ - End of string or line',
html => '<code> $ </code> - End of string or line',
html => '<code>$</code> - End of string or line',
heading => 'Regex Cheat Sheet',
),
'regexp \s' => test_zci(
'\s - Whitespace',
html => '<code> \s </code> - Whitespace',
html => '<code>\s</code> - Whitespace',
heading => 'Regex Cheat Sheet',
),
'regular expression [a-e]' => test_zci(
'[a-e] - Single character range (a or b ... or e)',
html => '<code> [a-e] </code> - Single character range (a or b ... or e)',
html => '<code>[a-e]</code> - Single character range (a or b ... or e)',
heading => 'Regex Cheat Sheet',
),
'regular expression [M-Y]' => test_zci(
'[M-Y] - Single character range (M or N ... or Y)',
html => '<code> [M-Y] </code> - Single character range (M or N ... or Y)',
html => '<code>[M-Y]</code> - Single character range (M or N ... or Y)',
heading => 'Regex Cheat Sheet',
),
'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)',
html => '<code>[3-5]</code> - Single character range (3 or 4 or 5)',
heading => 'Regex Cheat Sheet',
),
'regex [1-2]' => test_zci(
'[1-2] - Single character range (1 or 2)',
html => '<code> [1-2] </code> - Single character range (1 or 2)',
html => '<code>[1-2]</code> - Single character range (1 or 2)',
heading => 'Regex Cheat Sheet',
),
'regex [b-X]' => undef,
@ -68,7 +68,7 @@ ddg_goodie_test(
'regex foop [1-3]' => undef,
'regexp $' => test_zci(
'$ - End of string or line',
html => '<code> $ </code> - End of string or line',
html => '<code>$</code> - End of string or line',
heading => 'Regex Cheat Sheet'
),
);