The basic syntax of the js regular expression

1. The regular expression basic syntax

 two special symbols '^' and '$'. Their role is to indicate the beginning and end of a string, respectively.

Examples are as follows:

"^The": indicates all strings starting with "The" ("There", "The cat", etc.);

"of despair$": indicates a string that ends with "of despair";

"^abc$": a string indicating that both the beginning and the end are "abc" - huh, only "abc" itself;

"notice": means any string containing "notice".

Like the last example, if you don't use two special characters, you are saying that the string you are looking for is in any part of the string being searched - you
Do not position it at the top of a certain one.

There are three other symbols, '*', '+' and '?', indicating the number of times a character or a sequence of characters is repeated.

They mean "no or more", "one or more" and "no or one".
Here are a few examples:

"ab*": indicates that a string has an a followed by zero or several b. ("a", "ab", "abbb",......);

"ab+": indicates that a string has an a followed by at least one b or more;

"ab?": indicates that a string has an a followed by zero or one b;

"a?b+$": indicates that there are zero or one a followed by one or several b at the end of the string.

You can also use the range, enclosed in braces, to indicate the range of repetitions.

"ab{2}": indicates that a string has an a followed by two b("abb");

"ab{2,}": indicates that a string has an a followed by at least 2 b;

"ab{3,5}": indicates that a string has an a followed by 3 to 5 b.

Note that you must specify the lower bound of the range (eg: "{0,2}" instead of "{,2}").

Also, you may have noticed that '*', '+' and '?' are equivalent to "{0,}", "{1,}" and "{0,1}".

There is also a '¦' indicating an "or" operation:

"hi¦hello": indicates that there is "hi" or "hello" in a string;

"(b¦cd)ef": means "bef" or "cdef";

"(a¦b)*c": indicates a string of "a" "b" mixed strings followed by a "c";

'.' can replace any character:

"a.[0-9]": indicates that a string has an "a" followed by an arbitrary character and a number;

"^.{3}$": indicates a string of any three characters (3 characters in length);

Square brackets indicate that certain characters are allowed to appear at a specific position in a string:

"[ab]": indicates that a string has an "a" or "b" (equivalent to "a¦b");

"[a-d]": indicates that a string contains one of the lowercase 'a' to 'd' (equivalent to "a¦b¦c¦d" or "[abcd]");

"^[a-zA-Z]": indicates a string starting with a letter;

"[0-9]%": indicates a number before the percent sign;

",[a-zA-Z0-9]$": indicates that a string ends with a comma followed by a letter or number.

You can also use '^' in square brackets to indicate undesired characters, and '^' should be the first in square brackets.

(Example: "%[^a-zA-Z]%" means that no letters should appear in the two percent signs).

In order to express word by word, you must precede the characters "^.$()¦*+?{\" with the transfer character '\'.

Note that in square brackets, no escape characters are required. 

2. Regular examples of application examples of regular expressions

//Check if it is composed entirely of numbers

/^[0-9]{1,20}$/
^ indicates that the leading character must match the rule immediately following ^

$ means that the leading character is to match the rule immediately before $

The content in [ ] is an optional character set

[0-9] indicates that the required character range is between 0-9

{1, 20} indicates that the length of the numeric string is legally 1 to 20, that is, the number of occurrences of characters in [0-9] ranges from 1 to 20 times.
The /^ and $/ pairs should be used to represent rules that require the entire string to exactly match the definition, rather than just matching one substring in the string.
************************************************** *****************************

/ / Verify the login name: only enter 5-20 strings beginning with a letter, can carry a number, "_", "."

/^[a-zA-Z]{1}([a-zA-Z0-9]|[._]){4,19}$/
^[a-zA-Z]{1} indicates that the first character requirement is a letter.

([a-zA-Z0-9]|[._]){4,19} represents a string of length 4 to 9 starting from the second digit (because it is immediately following the previous expression) It is composed of uppercase and lowercase letters, numbers, or a special character set [._].
************************************************** *****************************

//Verify user name: only input 1-30 strings starting with a letter
/^[a-zA-Z]{1,30}$/
************************************************** *****************************
//Check password: only input 6-20 letters, numbers, underscores
/^(\w){6,20}$/
\w: used to match letters, numbers or underscore characters
************************************************** *****************************
/ / Verify ordinary phone, fax number: can start with "+" or a number, can contain "-" and " "
/^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/
\d: used to match numbers from 0 to 9;
The "?" metacharacter specifies that its leading object must appear consecutively zero or once in the target object.
Strings that can be matched are: +123 -999 999 ; +123-999 999 ;123 999 999 ;+123 999999 etc.
************************************************** *****************************
/ / Check the URL
/^http[s]{0,1}:\/\/.+$/ or /^http[s]{0,1}:\/\/.{1,n}$/ (for url string The length is length("https://") + n )
 \ / : indicates the character "/".
. Represents a set of all characters
+ is equivalent to {1,}, which is 1 to positive infinity.
 ************************************************** *****************************
/ / Verify pure Chinese characters
/

^[\u4E00-\u9FA5]+$/
[\u4E00-\u9FA5] : Estimated to be the scope of the Chinese character set.
The above expressions are tested in the following javascript via 

3. Regular expression application

"^\d+$" // non-negative integer (positive integer + 0)
"^[0-9]*[1-9][0-9]*$" //Positive integer
"^((-\d+)|(0+))$" // non-positive integer (negative integer + 0)
"^-[0-9]*[1-9][0-9]*$" //negative integer
"^-?\d+$" // integer
"^\d+(\.\d+)?$" //Non-negative floating point number (positive floating point number + 0)
"^(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\ .[0-9]+)|([0-9]*[1-9][0-9]*))$" //Positive floating point number
"^((-\d+(\.\d+)?)|(0+(\.0+)?))$" //Non-positive floating point number (negative floating point number + 0)
"^(-(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9] *\.[0-9]+)|([0-9]*[1-9][0-9]*)))$" //Negative floating point number
"^(-?\d+)(\.\d+)?$" //Float
"^[A-Za-z]+$" //a string of 26 English letters
"^[A-Z]+$" //String consisting of uppercase letters of 26 English letters
"^[a-z]+$" //a string consisting of 26 lowercase letters of English letters
"^[A-Za-z0-9]+$" //a string of numbers and 26 English letters
"^\w+$" //A string consisting of a number, 26 English letters, or an underscore
"^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$" //email address
"^[a-zA-z]+://(\w+(-\w+)*)(\.(\w+(-\w+)*))*(\?\S*)?$" // Url
/^(d{2}|d{4})-((0([1-9]{1}))|(1[1|2]))-(([0-2]([1- 9]{1}))|(3[0|1]))$/ // year-month-day
/^((0([1-9]{1}))|(1[1|2]))/(([0-2]([1-9]{1}))|(3[0 |1]))/(d{2}|d{4})$/ // month/day/year
"^([w-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|( ([w-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)$" //Emil
"(d+-)?(d{4}-?d{7}|d{3}-?d{8}|^d{7,8})(-d+)?" //Phone number
"^(d{1,2}|1dd|2[0-4]d|25[0-5]).(d{1,2}|1dd|2[0-4]d|25[0- 5]).(d{1,2}|1dd|2[0-4]d|25[0-5]).(d{1,2}|1dd|2[0-4]d|25[ 0-5])$" //IP address
^([0-9A-F]{2})(-[0-9A-F]{2}){5}$ //Regular expression of MAC address
^[-+]?\d+(\.\d+)?$ //Value Type Regular Expression