1. Definition: When detecting a text, you can use a pattern to describe what you want to detect, RegExp is this pattern.
2. Syntax: var patt=new RegExp (pattern,modifiers), or Var patt=/pattern/modifiers;
The pattern describes an expression model that describes whether the retrieval is global and case-sensitive.
3.REGEXP modifier to perform a case-insensitive match.
Example 1
Find "W3cschool" in strings that are case insensitive
var str= "Visit W3cschool";
var patt1=/w3cschool/i;
The text of the following markup is the matched expression obtained:
Visit W3cschool
Example 2
Full text find "is"
var str= "is the There is?";
var patt1=/is/g;
The text of the following markup is the matched expression obtained:
is th are allthere ?
Example 3
Full-text lookup and case insensitive search "is"
var str= "is the There is?";
var patt1=/is/gi;
The text of the following markup is the matched expression obtained:
is th are allthere ?
Test ()
The test () method searches for the value specified by the string, depending on the result and returns TRUE or false.
The following example searches for the character "E" from a string:
Instance
var patt1=new RegExp ("E");
document.write (Patt1.test ("The best things in life is free");
Because the letter "E" exists in the string, the output of the above code will be:
True
Regular character escaping rules (preceded by backslash \) are required when creating a regular object using a constructor function
Instance
var re = new RegExp ("\\w+");
EXEC ()
The EXEC () method retrieves the specified value in the string. The return value is the value that was found. If no match is found, NULL is returned.
The following example searches for the character "E" from a string:
Example 1
var patt1=new RegExp ("E");
document.write (Patt1.exec ("The best things in life is free");
Because the letter "E" exists in the string, the output of the above code will be:
E
Replication replication: https://www.2cto.com/kf/201601/487274.html
JavaScript REGEXP Objects