In many projects, we often need to use JS. The js replace () method is essential for modifying some elements at the front end of the page.
If you frequently use "ABCABCabc". replace ("A", "B"), you should be clear that the final result of the modified statement is BBCABC. This method can only be replaced
The first matched element. What if I replace all? Use a regular expression:
"ABCABCabc". replace (/A/g, "B.
What if I want to replace A with?
Then you can use "ABCABCabc". replace (/a/ig, "B ");
Flag: the size of the I-ID ignore is ignored, the g-ID global is repeatedly searched, and the m-ID multi-row retrieval (this is not tested yet)
You can also use their combination. For example, the ig used above replaces all the IDs and ignores the case.
Regular regular expression:
Var reg = new RegExp (/patten/flag)
Var strs = "". match (reg );
When the flag uses g, strs returns a string array.
If you want to match any one of multiple strings, you can use
Reg = new RegExp (/abc | xyz/ig );
From brilliant birds