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