1. Metacharacter:
Each regular expression is composed of metacharacters and modifiers
[Metacharacter] -> Some characters with meaning between two/
reg = /^\d$/ //It can only be a number between 0-9
1. Metachars with special meanings
\ : escape character, translate the meaning represented by the following characters
^ : Start with a meta character
$: End with a certain meta character
\n : Match a newline
. : Any character except \n
() : Grouping -> Divide a large rule itself into several small rules
x|y : one of x or y
[xyz] : one of x or y or z
[^xyz]: Any character except three
[a-z]: Any character between a-z
[^a-z] : Any character except a-z
\d : A character between 0-9 \D Any character except the number between 0-9
\b : A boundary symbol "w1 w2 w3"
\w : Any character in a number, letter, or underscore [0-9a-zA-Z_]
\s: Match a whitespace, a tab, page break...
2. Quantitle element characters representing the number of occurrences
*: Appears zero to multiple times
+: Appears 1 to 1 or more times
? : Zero or 1 occurrence
{n}: Appears n times
{n,} : Appears n to multiple times
{n,m} : Appear n to m times
var reg = /^\d+wo\d+$/;// 123wo234 var reg = /^(\d+)wo(\d+)$/; var reg = /^0.2$/ // Start with 0 and end with 2, and the middle can be any character except \nvar reg = /^\d+$/;//It can only be multiple numbers (('2017'))//true //A simple regularity for verifying mobile phone number: 11 digits, the first digit is 1 var reg = /^1\d{10}$/;
2. Metacharacter application
[]
1. All characters that appear in brackets are characters that represent their own meaning (without special meaning).
()
1. The role of grouping: Change the default priority of x|y
var reg = /^18|19$/; //There are 18, 19, 181, 189, 119, 819, 1819, 1819, 1819. var reg = /^(18|19)$/ //18、19
1. Regularity of effective numbers: positive numbers, negative numbers, zeros, decimals
1), "." can appear or not, but once it appears, one or more numbers must be followed.
2) At the beginning, there can be +/- or no
3) Integer part, a single digit can be one between 0 and 9, and a multi-digit number cannot start with 0.
The regularity is as follows
var reg = /^[+-]?(\d|([1-9]\d+))(\.\d+)?$/
The above is the regular metacharacter and some simple applications of JavaScript learning summary introduced by the editor to you. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support for my website!