Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of regular expression

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly shows you the "sample analysis of regular expressions", which is easy to understand and well-organized. I hope it can help you solve your doubts. Let me lead you to study and learn the article "sample Analysis of regular expressions".

-^ and $are used to match the beginning and end of a string, respectively. Example 1 ^ must start with a "" string Example 2$ must end with a string of "". Example 3 ^ abc$ begins with abc and ends with abc. In fact, only abc matches example 4 abc unsigned matches the string containing abc-* + and? Used to indicate the number or order in which a character can appear. They say-{0,} = * example 1 ab {0,} matching starts with an and then B appears Omurn times ("a", "ab", "abb", "abbbbbbbbbbbbbbbbb") Infinite.) {1,} = + example 2 ab {1,} matching starts with an and then B appears 1 ab N times ("ab", "abb", "abbbbbbbbbbbbbbbbb", infinity) {0meme1} =? Example 3 ab {0 ab 1} matching begins with an and then B appears once ("a", "Omer") example 4 a {0jue 1} b matches a string ending with 0 or 1 a plus a b. ("b", "ab") Note (two ways of writing) ab {0,} can also be written as ab*ab {1,} can also be written as ab+ab {0jue 1}, as ab?a {0pm 1} baud $, or as'*'+', and'?' Just control the number of times the character in front of it appears. 2 {Nab N} several to several times {0} O times 3 {} this cannot be negative (2) the number of times can be modified example 5 ab {2} requires that a be followed by two b (not less than one) such as ("abb"); example 6 ab {2,} requires that a be followed by two or more b ("abb", "abbbb", etc.) Example 7 ab {3 abbbbb 5} requires that there can be 5 b ("abbb", "abbbb", or "abbbbb") after a. (3) follow multiple characters with () example 8 a (bc) * match a followed by 0 or a "bc" Of course, you can also write "a (bc) {0" Example 9 a (bc) {1 bc 5} matches one to five "bc."-│ is equivalent to OR to represent one or more or -example 1 A │ B matches a string containing "A" or "B" Example 2 (A │ B) C matches a string containing "AC" or "BC" Example 3 (A │ B) * C match contains (including 0-1) an or b, followed by a c -. It can represent all the single characters. Do not include "\ n" spaces if there are spaces, but add a character to the space [\ n.] Multiple spaces + 1 characters [\ n\ n.] Example 1 a. [0-9] An a plus a character plus a number from 0 to 9 example 2 ^. {3} $three arbitrary characters end- The parentheses in'[ab] 'match only a single character-example 1 [ab] matches a single an or b (same as "a │ b") Example 2 [an abcd] matches a single character from'a'to'd'(the same effect as "a │ b │ c │ d" and "[abcd]") We usually use [a-zA-Z] to specify a character as an uppercase and lowercase English example 3 ^ [a-zA-Z] matches a string that begins with uppercase and lowercase letters 4 [0-9]% matches a string with a shape such as x% [a-zA-Z0-9] $matches a string ending with a comma plus a number or letter 6% [^ a-zA-Z]% matches a string containing two percent signs with a (non) letter in it. You can also list the characters you don't want in square brackets. You just need to use'^ 'point 1: ^ [content] ^ in the closing brackets to start with []. It means that the content begins with point 2: [^ content] ^ begins in []. It means excluding the content (^ non) point 3: match the string containing these characters. In square brackets [*\ +? {}.] Or the symbol will fail parentheses match only a single character point 4: [] contains'] 'preferably as the first character in the list (probably followed by' ^') point 5: [] contains'-'it's best to put it first or last, or or the'-'in the middle of the second end of a range [a-d-0-9] will be valid. -\ b and\ B 1 match a word right boundary 2 match a non-word boundary- -you can match the ve in love but not the ve in very: you can match the ov in love but not the ov- in ovry. -\ d and\ D- -example 1\ d matches a numeric character. Equivalent to [0-9]. Example 2\ D matches a non-numeric character. Equivalent to [^ 0-9]. -\ w and\ W- Example 1\ w matches any word character including an underscore. Equivalent to'[A-Za-z0-9 _] 'example 2\ W matches any non-word character including an underscore. Equivalent to'[^ A-Za-z0-9]'. -match non-print characters- -- character meaning\ 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 Amurz or aMuz. Otherwise, c is treated as a literal'c 'character. \ f matches a feed character. Equivalent to\ x0c and\ cL. \ nmatches a newline character. Equivalent to\ x0a and\ cJ. \ r matches a carriage return. Equivalent to\ x0d and\ cM. \ s matches any white space characters, including spaces, tabs, page breaks, and so on. Equivalent to [\ f\ n\ r\ t\ v]. \ s matches any non-white space character. Equivalent to [^\ f\ n\ r\ t\ v]. \ t matches a tab. Equivalent to\ x09 and\ cI. \ v matches a vertical tab. Equivalent to\ x0b and\ cK. -example- -- regular expression that matches the leading and trailing white space characters: ^ s * | matches the regular expression of the Email address: W + ([- +.] w +) * @ w + ([-.] w +) * .w + ([-.] w +) * matches the regular expression of the URL URL: [a-zA-z] +: / / [^ s] * matches whether the account is legal (beginning with the letter) Allow 5-16 bytes, alphanumeric underscore): ^ [a-zA-Z] [a-zA-Z0-9] {4G15} $match domestic phone number: d {3}-d {8} | d {4}-d {7} matching forms such as 0511-4405222 or 021-87888822 920-209642-964 match Tencent QQ number: [1-9] [0-9] {4,} 1 + That is, 10000 matches China Postal Code: [1-9] d {5} (?! d) China Postal Code matches 6 digits ID card: d {15} | d {18} commentary: Chinese ID card matches ip address for 15 or 18 digits: dong.dan.d + comment: useful when extracting ip address-- -^ $/ / from the beginning to the end + / / 1 consecutive (connected) (that is,-{1 }) -? / indicates negative and non-negative (that is,-{0ret 1}) [0-9] * / / indicates the preceding digit 0murn (i.e. [09] {0) }). / / indicates a bit or no dot [^ / / the content inside [Amurz] / / matches all lowercase letters [Amurz] / / matches all uppercase letters [a-zA-Z] / / matches all letters [0-9] / / matches all digits 0-9 integers [0-9 -] / / matches all numbers Full stop and minus sign-^ [a-zA-Z0-9 _] + $/ / all contain more than one letter, Numeric or underlined string / / example concatenated aA0_A001a_ ^ [0-9] + $/ / all positive numbers (non-negative integers) / / example 3455006870080999009999 ^ -? [0-9] + $/ / all integers (including negative and integer) / / example-43443 or 43443 ^ -? [0-9] *. [0-9] * $/ all integers Decimal (including the infinite length of the number of decimal places before and after the decimal point) / / for example-100000.0000 or 10.00 if there is no decimal point, there must be no number after the decimal point. So add a..? To judge whether there is a decimal point, it is reasonable not to need. It's superfluous because this is used to judge decimals, if there is no decimal point. All characters except lowercase [^ / ^] / all characters except "/" and "^" characters [^ "] / / all characters except double quotation marks (") and single quotes (') are all the contents of the article "sample Analysis of regular expressions". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report