1. The function of regular expression
Regular expressions, which are used to match strings, are checked for certain formats, and can be grouped by format, replacing ... In fact, no regular expression, can also be compiled. However, in most cases, regular expressions can improve the efficiency of your programming.
2. Source of study
(1) network resources. (2) Through the JDK API, search for the pattern, including some simple usage, some simple regular expressions can be written out.
3. Regular grammar Introduction
Regular current personal level I use more than two places, one is the page input, the regular check, such as mobile phone number, mailbox, some must be data of the place to verify. There is the background of the data processing needs to be verified (here I am involved a little bit less).
(1) Character class
1) [ABC] indicates that a, B and C have a compliance.
2) [^ABC] denotes any field except A, B, and C.
3) [a-za-z] denotes a to Z or A to Z, and the letters at both ends are included (range).
4) [0-9] means 0 to 9 characters are included
(2) Pre-defined character classes
1). Any character. If you have to. ,\.
2) \d and [0-9] indicate the same
3) \w Word character: [a-za-z_0-9]
(3) Boundary match 1) ^ Start of line
2) End of the $ line
3) \b The boundary of the word
(4) Quantity words
1) X? Indicates that x does not once or once.
2) x* means X 0 or more times.
3) x+ means X one or more times.
4) X{n} indicates that X is exactly n times.
5) X{n,} means X at least n times.
6) X{n,m} indicates that X is at least n times, but not more than m times.
4, simple small example
(1) QQ number
[1-9] [0-9] {4,11}
Indicates that the first bit is a random bit in 1 to 9, followed by a random number of digits from 0 to 9, a total of at least 4 bits, and a maximum of 11 bits.
(2) Mobile phone number
1[3578][0-9]{9}
The first digit is 1, the second is in 3,5,7,8, and the next 9 bits are randomly in 0 to 9.
(3) Email
\\[email protected]\\w{2,7} (\\.\\w{2,4}) +
\ \ means \
\\w represents a random bit in [a-za-z_0-9].
+ represents x once or more times.
The @ symbol is followed by a \\w that is randomly 2 to 7 bits in [a-za-z_0-9]
\ \. said.
(\\.\\w{2,4}) + in + indicates possible. The appearance of com.cn and other conditions
(4) Check the phone number of the page before the instance is submitted
get the phone number.
var phone = $ ("#contactway"). Val ();
Alert ("The phone number is wrong, please re-fill");
}
var c = $ ("#acreage"). Val ();
Alert (" please fill in the correct area format");
5. Message
Here are some basic small knowledge, if you are interested in the Internet there is more and deeper knowledge. Enrich themselves, everyone is always in the state of learning, each day to learn a little knowledge, they will be more comprehensive.
Regular expressions for Java-learning