Regular expressions are enclosed in matching pound sign (#
) characters with a prepended re
: re#...#
. KRL regular expressions follow the JavaScript standard, which closely follows the conventions for Perl regular expressions. The following modifiers may appear in any order after the closing character:
...
Like strings, the only special character is #
. To characters are the terminator (#
) and the backslash (/
). To use a pound sign or a backslash inside a regular expression, escape it them with a backslashbackslashes:
Code Block | ||||
---|---|---|---|---|
| ||||
re#\##\#\\# // '#' followed by '\' |
A newline (\n) requires a line break:
...
KRL uses the hash character to delimit regular expressions instead of the more common (and acceptable) slash (/
) because the slash is a frequently used character in URL paths. This removes the need to quote the slash with backslashes: re/\/archives\/\d{4}\//
. Using an alternate delimiter makes the regex more readable and thus communicates its meaning more clearly.
Issues
...