Skip to main content

replace

Replace each match with the specified string.

const str = "The rain in Spain stays mainly in the plain.";
regex.replace("(ain)", str, "xxx"); //"The rxxx in Spxxx stays mxxxly in the plxxx."

Syntax

replace(pattern, source, target)

Returns

The new string.