regex.replace_all()
regex.replace_all(haystack, pattern, replacement) replaces all occurrences of a regex pattern in a string with a replacement string.
Returns
if
haystackandreplacementare strings andpatternmatches, returns a new string with all matches replaced byreplacement.otherwise, returns
null.
Examples
// normalize multiple spaces
regex.replace_all(text, /\s+/, " ")
// redact sensitive data
regex.replace_all(log, /\d{3}-\d{2}-\d{4}/, "XXX-XX-XXXX")
// rewrite dates from MM/DD/YYYY to YYYY-MM-DD
regex.replace_all(dates, /(\d{2})\/(\d{2})\/(\d{4})/, "$3-$1-$2")Last updated
Was this helpful?