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 after the closing character:
i
. The i modifier makes the regular expression case insensitive.g
. The g modifier applies the regular expression globally.
For example, the following code replaces the first instance of foo
in p
with bar
:
p.replace(re#foo#, "bar")
In contrast, the following code replaces all instances of foo
in p
with bar
:
p.replace(re#foo#g, "bar")