Replace method on strings

I have googled this and read the w3c school page as well as MDN web tools page but the syntax of it still confuses me.

the syntax of it should be something like this:

string.replace(regexp/substr, newSubStr/function[, flags]);

so… what does regexp mean?? which one is replacing which??

could someone list me some examples of this replace method?

did we learn this in freecodecamp challenges? I sort of remembering learning it but could not find it.

RegExp means Regular expression (here a link to MDN MDN - RegExp.

What the string you posted means is that you can use a substring OR a regular expression to find the string to replace, and a new subStr OR a function as 2nd argument to replace with.

Just to be sure when you say you have googled the MDN web tools page are you speaking of this one?
MDN - String.prototype.replace
Because there you can find few examples from the simplest to some more complex ^^

1 Like