Regular Expression Learning Diary Select Blog from Zhaoqiubo

xiaoxiao2021-03-05  23

1. "." Is a wildcard, indicating any character, for example: "ac" can match "ANC", "ABC", "ACC"; 2, "[]", in [], you can specify the matching character, For example: "A [NBC] C" can match "ANC", "ABC", "ACC"; but can not match "ANCC", A to Z can be written into [AZ], 0 to 9 can be written [0-9] 3, quantity defined symbols, indicating symbols of matching (or length): "*" - 0 times or multiple " " - 1 or multiple times "?" - 0 times or 1 time "{N}" - Match n times, n is an integer "{n, m}" - matches a number of times between N to M; N and M are integers; "{n,}" - Match N to infinity between the number; "{, M}" - Match 0 to m between arbitrary number; they put it behind the matching format: for example: phone number: 024-84820482, 02484820482 (Assumption front 3 or 4 bits, rear 7 or 8 bits, and the middle minus can be proven to match, then it can be matched with the following format: [0-9] {3, 4} / -? [0 -9] {7, 8}; Note: "/" is a escape character, because "-" In the regular expression, the meaning represents a range of scope, for example, what is said, it needs The escape character "/" is used to use; 4, "^" is indicated by the symbol, indicating that the symbols do not want to match, for example: [^ z] [AZ] can match all except "Z" starting String (length greater than 2, because " " indicates that the number of times equal to 1, from the second bit is lowercase English characters); if ^ placed outside [], it means the string starting with []; ^ [ AZ] [AZ] represents the length of the length of A or Z is greater than or equal to 2, "|" or operator, for example: a [N | BC | CB] c can match "ABCC", "ANC" "ACBC"; 6, "$" ends with its previous characters; for example: AB $, "ABB", "AB" match; 7, some simple representation: / D represent [0-9]; / D indicates that [^ 0-9]; / w Represents [A-Z0-9]; / W Represents [^ A-Z0-9]; / s indicates [/ t / n / r / f], it is a space character Including Tab, Space, etc.; / s indicates that [^ / T / N / R / F] is non-space character; 8, common match: match Chinese characters: "[/ u4e00- / u9fa5]"; match double word The characters (including Chinese characters): "[^ / x00- / xff]"; Match the regular expression of the blank line: "/ n [/ s |] * / r"; regular expression that matches HTML tag: " /< (.*)>.* | <(. *) //> / "; Regular expression of matching the first tail space:" (^ / s *) | (/ s * $) "; match non-negative integer (positive integer 0):" ^ / d $ "; match positive integer:" ^ [0-9] * [1-9] [0-9] * $ "; matching non-positive integer (negative integer 0):" ^ | (0 )) $ "; matching negative integence:

转载请注明原文地址:https://www.9cbs.com/read-33075.html

New Post(0)