Regular expression of ES5 Foundation 01: First Meeting

Source: Internet
Author: User

1. Regular first meeting

Test Address: https://regexper.com

First regular: Match 2006-10-11 or 2006/10/11

var reg =/^\d{4}[-/]\d{2}[-/]\d{2}$/;

The above notation means that a regular object is created using literals

There is, of course, a way to create a regular expression by using the RegExp () constructor.

    //Online test tool: https://regexper.com/    //First regular match: 2006-10-11 or 2006/10/11    varReg =/^\d{4}[-/]\d{2}[-/]\d{2}$/; /*RegExp Object * JavaScript supports regular expressions through built-in object RegExp * There are two ways to instantiate a RegExp object * 1. Literal * 2. Constructors*/    /*1. Replace the string: Replace the word is with is * here by default matches the first one*/    varString = ' This is a girl '; String= String.Replace (/\bis\b/, ' is '));    Console.log (string); //\b (Word) \b is a word that matches a complete word;    //so how to achieve the full text? Use modifier g    varString = ' This is a girl '; String= String.Replace (/\bis\b/g, ' is '));    Console.log (string); /*2. Using the constructor * var reg = new RegExp (string,) * Constructor REGEXP () accepts two parameters, the first is regular, the second is a modifier*/    varReg =NewREGEXP (' \\bis\\b ', ' g '); /*3. Modifier * G:global, indicates full-text search, if not added then search to first stop * i:ignore, ignore case, default case sensitive * M:multipul lines multi-line match*/    //Test modifier i    varString = ' This is a girl '; String= String.Replace (/\bis\b/g, 0);    Console.log (string); //the above will only replace the first is with a 0    //Test modifier i    varString = ' This is a girl '; String= String.Replace (/\bis\b/gi, 0);    Console.log (string); //The above will replace two is with 0, because I makes the matching pattern insensitive to case

Regular expression of ES5 Foundation 01: First Meeting

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.