regex.replace()
regex.replace(haystack, pattern, replacement) replaces the first occurrence of a regex pattern in a string with a replacement string.
Returns
if
haystackandreplacementare strings andpatternmatches, returns a new string with the first match replaced byreplacement.otherwise, returns
null.
Examples
// remove leading whitespace
regex.replace(text, /^\s+/, "")Last updated
Was this helpful?