regex_replace()
Perform a regular expression replace
regex_replace(pattern, subject, replacement, case_sensitive = false)
pattern
(string) — Regex pattern to search for. The pattern follows the ECMAScript syntaxsubject
(string) — The target sequencereplacement
(string) — The replacement stringcase_sensitive
(boolean, optional) — If case_sensitive
is true
then regex is performed with regard to case. The default value is false
string
— Returns the replaced string
import regex
pattern = "(\w+)@(\w+)\.com"
subject = "clara@yahoo.com; sarah@gmail.com; ana@icloud.com"
replace_to = "$1 on email $2"
regex_replace(pattern, subject, replace_to)
' Returns "clara on email yahoo; sarah on email gmail; ana on email icloud"