Briefly describe the use of regular expressions in JavaScript, javascript Regular Expressions
A regular expression is an object that describes the character mode.
The RegExp class in JavaScript represents regular expressions, strings, and regular expression definitions, and uses regular expressions for powerful pattern matching and searching and replacing text functions.
Syntax:
You can use RegExp () to construct a regular expression:
var pattern = new RegExp(pattern, attributes);or simplyvar pattern = /pattern/attributes;
Here is a description of the parameters:
- Pattern: a string that specifies the pattern of a regular expression or other regular expressions.
- Attributes: contains any "g", "I", and "m" attributes that specify the global, an optional string, case-insensitive and matching.
Brackets:
Brackets ([]) are special when used in the context of a regular expression. They are used to find the range of characters.
The range shown above is general. You can also use the range [0-3] to match any decimal number through 3 from 0, or the range [B-v] matches any lowercase letter, from B to v
Qualifier:
The frequency or Character Sequence in square brackets and the position of a single character can be expressed by a special character. Each special character has a specific meaning. In + ,*,?, And the $ flag both follow a character sequence.
Example:
The following example clears the concept of matching characters.
Literal characters:
The metacharacter is only followed by a backslash. It is used to make the combination contain letters with special meanings.
For example, you can use the '\ d' metacharacters to search for a large total amount of currency:/([\ d] +) 000/. Here \ d searches for any string of numeric characters.
The following are metacharacters that can be used in Perl-style regular expressions.
Modifier
Several modifiers are available, making work and regular expressions much easier, such as case sensitivity and searching for multiple rows.