How to remove double quotation marks using a JavaScript Regular Expression and remove double quotation marks using a regular expression

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.