RegExp: is the abbreviation of regular expression.
What is RegExp?
Regular expressions describe character pattern objects.
When you retrieve some text, you use a pattern to describe what you want to retrieve. RegExp is this pattern.
Simple patterns can be a single character.
More complex patterns include more characters and can be used for parsing, format checking, substitution, etc.
You can specify where in the string to search, what type of characters to search for, and so on.
Grammar
var patt=new RegExp(pattern,modifiers);
or
var patt=/pattern/modifiers;
A pattern describes an expression model.
Modifiers describe whether the search is global, case-sensitive, etc.
RegExp modifier
The modifier is used to perform case-insensitive and full-text searches.
Example 1
Look for "W3CSchool" in the string without case sensitivity
var str="Visit W3CSchool"; var patt1=/w3cschool/i;
The following marked text is the obtained matched expression:
Visit W3CSchool
Example 2
Full text search "is"
var str="Is this all there is?"; var patt1=/is/g;
The following marked text is the obtained matched expression:
Is this all there is?
Example 3
Full-text search and case-insensitive search for "is"
var str="Is this all there is?"; var patt1=/is/gi;
The following marked text is the obtained matched expression:
Is this all there is?
Let’s take a look at some of the basic regular expression objects available in JS:
Modifier
Modifiers used to perform case-sensitive and global matching:
Square brackets
Square brackets are used to find a range of characters:
Metacharacters
Metacharacters are characters with special meanings:
Quantifier
RegExp object method
Methods of String objects that support regular expressions