I would like to replace all characters in a string myString
with "p", except "o".
For example:
"fgyerfgehooefwfweeo"
should become
"pppppppppoopppppppo"
I tried:
myString.replaceAll('[^o]*/g', 'p')
replace
(or replaceAll
).*
after the character class; otherwise, multiple consecutive characters that are not "o" will be collapsed into a single "p".let str = "fgyerfgehooefwfweeo";
let res = str.replace(/[^o]/g, 'p');
console.log(res);