How to remove double quotation marks using a JavaScript Regular Expression and remove double quotation marks using a regular expression
Recently, I took over a project. The project needs to use the js regular expression to filter out the double quotation marks worth in the text field of the page. In fact, the solution is very simple. I will share the code I wrote to you below, if you have the same requirements, refer.
The specific solution code is as follows:
<Html> <script language = "javascript"> // var pattern =/[^ "] */; // check whether all strings contain the character var pattern =/["] + /; // check whether the character string contains double quotation marks. // var pattern =/["] [^"] * ["] // match the value 0 that is enclosed in single or double quotation marks. var value1 = "The best things in life are free "; // The string var value2 = "/"/"The/" best things/"in life are free /"/""; // string alert with double quotation marks ("value1 string without double quotation marks pattern.exe c_1 =" + pattern.exe c (value1); // null alert ("value1 No String with double quotation marks! Pattern.exe c_2 = "+! Pattern.exe c (value1); // true alert ("value2 string with double quotation marks pattern.exe c_1 =" + pattern.exe c (value2 )); // "" alert ("value2 is a string with double quotation marks! Pattern.exe c_2 = "+! Pattern.exe c (value2); // false if(pattern.exe c (value1 )) {// check whether all the characters in the string are non-double quotation marks ("value1 is not added with a non-double quotation mark");} if (! Pattern.exe c (value1) {// check whether the string contains the double quotation mark character alert ("value1 has a non-sign + ++ + double quotation mark matched "); // page pop-up} if(pattern.exe c (value2 )) {// check whether all characters in the string are non-double quotation marks ("value2 is not added with a non-sign ++ + double quotation marks "); // page pop-up} if (! Pattern.exe c (value2) {// check whether the string contains the double quotation mark character alert ("value2 has a non-sign ++ double quotation mark matched ");} </script>
The above code has been tested by the IE 8 browser. I hope it will be helpful to anyone who has encountered such problems in the future.