This article mainly introduces the use of the JavaScript in the regular expression, the regular expression is the important knowledge of JS advanced Learning, this article briefly describes the support for the regular expression JS, the need for friends can refer to the
A regular expression is an object that describes the character pattern.
The RegExp class of JavaScript represents regular expressions and string and regular expression definitions, using regular expressions for powerful pattern matching and searching and replacing text functionality.
Grammar:
A regular expression can construct such a definition with RegExp ():
?
1 2 3 4 5 |
var pattern = new RegExp (pattern, attributes); or simply var pattern =/pattern/attributes; |
Here is the description of the parameter:
Pattern: A string that specifies patterns for regular expressions or other regular expressions.
Attributes: Contains any "G", "I", and "m" attributes specify Global, an optional string, case-insensitive and matched.
Brackets:
parentheses ([]) have special meaning when used in the context of a regular expression. They are used to look up the range of characters.
The range shown above is general; You can also use the range [0-3], by 3 matches any decimal number from 0, or range [b-v] matches any lowercase letter, from B to V
Qualifier:
The frequency or the position of a character sequence in square brackets with a single character can be represented by a special word. Each special character has a specific connotation. In +, *,?, and $ flags are followed by a sequence of characters.
Example:
The following example clears the concept of matching characters.
Literal characters:
The metacharacters is simply preceded by a backslash, which is the function of making a combination of alphabetic characters with special meanings.
For example, you can use the ' d ' character to search for a large sum of money:/([D]+) 000/, where D will search for any string of numeric characters.
The following is a meta character, a list that can be used in a Perl-style regular expression.
Modifiers
Several modifiers are available to make working with regular expressions much easier, such as capitalization, searching for multiple rows, and so on.