regex.replace(haystack, pattern, replacement) replaces the first occurrence of a regex pattern in a string with a replacement string.
regex.replace(haystack, pattern, replacement)
if haystack and replacement are strings and pattern matches, returns a new string with the first match replaced by replacement.
haystack
replacement
pattern
otherwise, returns null.
null
// remove leading whitespace regex.replace(text, /^\s+/, "")
Last updated 1 month ago
Was this helpful?