This article describes how to replace the content in a string with a regular expression in JavaScript, and provides a brief comment for ease of understanding. It has a certain reference value. If you need a friend, you can read more. Please refer to the specific implementation code.
// Cut the 'is: var str = 'Is all there is' from the string 'is this all there Is'; var subStr = new RegExp ('ais '); // create a regular expression object var result = str. replace (subStr, ""); // replace 'is with an empty string console. log (result); // Is th all there is var subStr = new RegExp ('is', 'I'); // create a regular expression object, case Insensitive var result = str. replace (subStr, ""); // replace 'is with an empty string console. log (result); // this all there is var subStr = new RegExp ('is', 'ig '); // create a regular expression object, case insensitive, global Search var result = str. replace (subStr, ""); // replace 'is with an empty string console. log (result); // th all there var subStr =/is/ig; // create a regular expression object by using the direct method, which is case-insensitive. Global Search for var result = str. replace (subStr, ""); // replace 'is with an empty string console. log (result); // th all there console. log (str); // Is this all there is visible replace does not change the original str
The above is all the content of this article. I hope this article will help you in your study or work, and I also hope to support PHP!
For more articles about how JavaScript uses regular expressions to replace the content in a string, refer to PHP!