Regular expression rules

Source: Internet
Author: User

^ is the delimiter that represents the beginning of the matching string;
[+-], the brackets indicate that the contents are matched to the requirements, so this means "+" or "-";
\D,[0-9] abbreviated form, that is, matching numbers;
$ is also the delimiter that represents the end of the matching string;

See the question mark (?) after you know the above. and asterisk (*): Following a pattern content is a quantifier, used to limit the number of pattern content matching, for example, I want to match a minimum of 1, a maximum of 3 numbers, such as 4, 20, 123, 226 such as, previously explained that a single number can be expressed in [0-9] or \d, So how do you mean a minimum of 1 matches, up to 3 times? Very simple, just after the pattern with curly braces to denote quantifiers, in the form of {lower bound, upper limit}, that is the case [0-9]{1,3} or \d{1,3}. Similarly, [0-9]{2} means that only 2 digits can be matched (one less than the other), [0-9]{2,} indicates at least 2 digits (note the comma within the curly braces), and [0-9]{,2} represents a maximum of 2 digits (note the comma of the curly braces).
For frequently used quantifiers
There is also a shorthand in the regular, {0,1} shorthand is a question mark (either no or only once)
{0,} shorthand is an asterisk (any number or unlimited)
{1,} shorthand is a plus sign (at least once)

. * denotes any number of arbitrary characters for example: A.*b, which will match the longest string starting with a and ending with B. If you use it to search for Aabab, it will match the entire string aabab. This is called a greedy match.
Sometimes we need more lazy matching, which is to match as few characters as possible. The qualifier given above can be converted to lazy matching mode, just add a question mark after it. So. * is meant to match any number of repetitions, but with minimal repetition in the premise that the entire match succeeds
A.*?b matches the shortest, starting with a string ending with B. If you apply it to Aabab, it will match AaB (first to third character) and AB (fourth to fifth characters)
The *, +, and? Qualifiers are greedy because they match as many words as possible, but only after they are added with one? You can implement a non-greedy or minimal match.

^ matches the starting position of the input string, unless used in a square bracket expression, which indicates that the character set is not accepted
() to mark the start and end of a sub-expression

\CX matches the control character indicated by X. For example, \cm matches a control-m or carriage return. The value of x must be one of a-Z or a-Z. Otherwise, c is treated as a literal ' C ' character.
\f matches a page break. Equivalent to \x0c and \CL.
\ n matches a line break. Equivalent to \x0a and \CJ.
\ r matches a carriage return character. Equivalent to \x0d and \cm.
\s matches any whitespace character, including spaces, tabs, page breaks, and so on. equivalent to [\f\n\r\t\v].
\s matches any non-whitespace character. equivalent to [^ \f\n\r\t\v].
\ t matches a tab character. Equivalent to \x09 and \ci.
\v matches a vertical tab. Equivalent to \x0b and \ck.

Regular expression rules

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.