JavaScript uses regular expressions to replace content in strings _javascript tips

Source: Internet
Author: User

Don't say much, please see the specific implementation code

There ' is ' in the string ' is ': ' The Var str= ' is ' is '
 ;
 var substr=new RegExp (' is ');//Create Regular Expression object
 var result=str.replace (subStr, "");//replace ' is ' with an empty string
 console.log ( result);//is th all there
 are var substr=new RegExp (' is ', ' I ');//create regular Expression objects, case-insensitive
 var result=str.replace (subStr , "");//replace ' is ' with an empty string
 console.log (result);//this all there
 are var substr=new RegExp (' is ', ' IG ');//create regular Expression object. Case-insensitive, global lookup
 var result=str.replace (subStr, "");//replace ' is ' with empty string
 console.log (result);//th all there 
 var substr=/is/ig;//Direct method to create regular expression objects, case-insensitive, global lookup
 var result=str.replace (subStr, "");//replace ' is ' with an empty string
 Console.log (result);//th all there 
 console.log (str);//is The all there is visible replace does not change original STR

The above is the entire content of this article, I hope the content of this article for everyone's study or work can bring some help, but also hope that a lot of support cloud Habitat community!

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.