Replaces the first instance of a string or regular expression.
Implemented with the built-in String.replace(), which allows for additional features documented at MDN (e.g., special patterns in the replacement strings).
import * as S from "flurp/string";const underscoreForE = S.replace("e", "_");const vowelToUpper = S.replace(/[aeiou]/, S.toUpperCase);underscoreForE("weasel"); // "w_asel"vowelToUpper("weasel"); // "wEasel"
(if RegExp, must include the global flag)
Replaces the first instance of a string or regular expression.
Remarks
Implemented with the built-in String.replace(), which allows for additional features documented at MDN (e.g., special patterns in the replacement strings).
Example