Basic knowledge about regular expressions

Source: Internet
Author: User

1. ". "is a wildcard that represents any character, for example,". c can match "anc", "abc", and "acc". 2. "[]". You can specify the matching characters in []. For example: "a [nbc] c" can match "anc", "abc", and "acc", but it cannot match "ancc". a to z can be written as [a-z], 0 to 9 can be written as [0-9]; 3. quantity limit symbol, indicating the number of matches (or length): including: "*" -- 0 or multiple times "+" -- 1 or multiple times "?" -- 0 times or 1 time "{n}" -- match n times, n is an integer "{n, m}" -- the number of times a number from n to m is matched; both n and m are integers; "{n ,}" -- match any number of times between n and infinity;" {, m} "-- match any number of times between 0 and m; they are placed behind the matching format: for example, the phone number: 024-84820482,02484820482 (assume that the first 3 or 4 digits, the last 7 or 8 digits, and the minus signs in the middle are optional, the following format can be used for matching: [0-9] {3, 4 }\\-? [0-9] {}; note: "\" is an escape character, because "-" represents a range in a regular expression, for example: as mentioned above [0-9], it must escape the character "\" for conversion. 4. "^" indicates no, indicating that it does not want to match, for example, [^ z] [a-z] + can match all character strings except those starting with "z" (length greater than 2, because "+" indicates the number of times greater than or equal to 1, and is a lowercase English character from the second digit); If ^ is placed outside [], it indicates a string starting; ^ [az] [a-z] + indicates an English character string starting with a or z with a length greater than or equal to 2; 5, "|", or operator, for example: a [n | bc | cb] c can match "abcc", "anc", and "acbc". 6. "$" ends with the character before it. For example: AB + $ can be matched by "abb" and "AB". 7. Some Simple Representation Methods: \ d indicates [0-9]. \ D represents [^ 0-9]; \ w represents [A-Z0-9]; \ W represents [^ A-Z0-9]; \ s represents [\ T \ n \ r \ f], that is, the space characters include tab, space, and so on; \ S indicates [^ \ t \ n \ r \ f], which is a non-space character. 8. Common matching: matching Chinese characters: "[\ u4e00-\ u9fa5]"; matching double-byte characters (including Chinese characters): "[^ \ x00-\ xff]"; regular Expression matching empty rows: \ n [\ s |] * \ r; Regular Expression matching HTML tags: "/. * |/"; Regular Expression matching the first and last spaces:" (^ \ s *) | (\ s * $) "; match non-negative integer (positive integer + 0 ): "^ \ d + $"; matches a positive integer: "^ [0-9] * [1-9] [0-9] * $ "; match a non-positive integer (negative integer + 0): "^ (-\ d +) | (0 +) $"; match a negative integer: "^-[0-9] * [1-9] [0-9] * $"; matching INTEGER: "^ -? \ D + $ "; match non-negative floating point number (Positive floating point number + 0):" ^ \ d + (\. \ d + )? $ "Matches Positive floating point:" ^ ([0-9] + \\. [0-9] * [1-9] [0-9] *) | ([0-9] * [1-9] [0-9] * \. [0-9] +) | ([0-9] * [1-9] [0-9] *) $ "; ^ (-\ d + (\\. \ d + )?) | (0 + (\. 0 + )?)) $ // Match a 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] *) $ // match the negative floating point number to match the Floating Point Number: "^ (-? \ D +) (\. \ d + )? $ "; Matches the string consisting of digits, 26 English letters, or underscores:" ^ \ w + $ "; matches the email address: "^ [\ w-] + (\\. [\ w-] +) * @ [\ w-] + (\\. [\ w-] +) + $ "; matched url:" ^ [a-zA-z] +: // match (\ w + (-\ w + )*)(\\. (\ w + (-\ w + )*))*(\\? \ S *)? $ "1,". "is a wildcard that represents any character, for example,". c can match "anc", "abc", and "acc". 2. "[]". You can specify the matching characters in []. For example: "a [nbc] c" can match "anc", "abc", and "acc", but it cannot match "ancc". a to z can be written as [a-z], 0 to 9 can be written as [0-9];...

Related Article

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.