I recently took on a project. The project needs to use js regular expressions to filter out double quotes in the text field of the page. In fact, the solution is very simple. Let me share the code I wrote with you below. Friends who have the same needs can refer to it.
The specific solution code is as follows:
<html> <script language="javascript"> //var pattern = /[^"]*/; //Check whether the string is not double quoted characters var pattern = /["]+/; //Check whether there are double quote characters in the string //var pattern = /["][^"]*["]/ //The match is 0 or more characters within single or double quotes var value1 = "The best things in life are free"; //String without double quotes var value2 = "/"/"The /"best things /"in life are free/"/""; //Stand with double quotes alert("value1String without double quotes pattern.exec_1===" + (value1)); //null alert("value1String without double quotes !pattern.exec_2===" + !(value1)); //true alert("value2String with double quotes pattern.exec_1===" + (value2)); //"" alert("value2String with double quotes !pattern.exec_2===" + !(value2)); //false if((value1)){ //Check whether the string is not double quoted characters alert("value1 has no non-sign ++++++++ double quotes are matched"); } if(!(value1)){ //Check whether there are double quote characters in the string alert("value1 has a non-sign ++++++++ double quotes are matched"); //The page window pops up } if((value2)){ //Check whether the string is not double quoted characters alert("value2 has no non-sign ++++++++ double quotes are matched"); //The page window pops up } if(!(value2)){ //Check whether there are double quote characters in the string alert("value2 has a non-sign ++++++++ double quotes are matched"); } </script> </html>
The above code has been tested by IE8 browser. I hope it will be helpful to friends who encounter this similar problem in the future.