regex | string
The regex to perform replacements on
Replacement for each matches location
Matches all occurences of
If value is a string. It is matched as appears in the string gloablly, it is not converted to a regular expression.
A regular expression's capture groups are passed to the replacement if applicable.
If the replacement is a string, the following charcater sequences have special behavior:
Inserts a literal
Refers to the entire matches string
Refers to the match the precedes the given match
Refers to the match that follows the given match
If the replacement is a function, the capture groups are passed in the format
( c1, c2, ..., cn ). The function should return string, otherwise an error will be thrown
"1 + 1 = 2".sub(/\d+ ([+*/-]) \d/g, "$1") == "+ = 2""1 + 1 - 2".sub(/(\d+ )?([+-]) \d+/g, "$'") == " - 2 ""Hi".sub("i", "ello") == "Hello"