Computes a new version of a String value in which certain characters have been escaped, so that the regular expression engine will interpret any metacharacters that it may contain as character literals.
When the escape function is called with one argument string, the following steps are taken:
- Let string be ToString(string).
- ReturnIfAbrupt(string).
- Let length be the number of characters in string.
- Let R be the empty string.
- Let k be 0.
- Repeat, while k < length,
1. Let C be the character at position k within string.
1. If C is one of the 16 nonblank characters "-[]{}()*+?.,\^$|" then,
- Let S be a String containing two characters "\x" where x is a C character. 1. Else,
- Let S be a String containing the single C character. 1. Let R be a new String value computed by concatenating the previous value of R and S. 1. Increase k by 1.
- Return R.
@inexorabletash
Good point. Only SyntaxCharacter doesn't have
-
and,
.I thought about this as well, but saw that
escape
gives a list of characters as well, so left it as is. Or do you mean to rephrase "If char is the code point of one of the 16 nonblank characters"?@zloirock
Thanks, fixed :)