当前位置:网站首页>Regular expression syntax and common regular expressions
Regular expression syntax and common regular expressions
2022-04-21 09:27:00 【Yunmeng GUIYAO】
Complete set of regular expression syntax
| character | describe |
|---|---|
| \ | Mark the next character as a special character 、 Or an original character 、 Or a backward reference 、 Or an octal escape character . for example ,“n” Matching character “n”.“\n” Match a line break . Serial “\\” matching “\” and “\(” The match “(”. |
| ^ | Matches the start of the input string . If set RegExp Object's Multiline attribute ,^ Also match “\n” or “\r” The position after . |
| $ | Matches the end of the input string . If set RegExp Object's Multiline attribute ,$ Also match “\n” or “\r” Previous position . |
| * | Match previous subexpression zero or more times . for example ,zo* Can match “z” as well as “zoo”.* Equivalent to {0,}. |
| + | Match previous subexpression one or more times . for example ,“zo+” Can match “zo” as well as “zoo”, But can't match “z”.+ Equivalent to {1,}. |
| ? | Match previous subexpression zero or once . for example ,“do(es)?” Can match “does” or “does” Medium “do”.? Equivalent to {0,1}. |
| { n} | n Is a non negative integer . Matched definite n Time . for example ,“o{2}” Can't match “Bob” Medium “o”, But it matches “food” Two of them o. |
| { n,} | n Is a non negative integer . Match at least n Time . for example ,“o{2,}” Can't match “Bob” Medium “o”, But it can match. “foooood” All in o.“o{1,}” Equivalent to “o+”.“o{0,}” Is equivalent to “o*”. |
| { n,m} | m and n All non negative integers , among n<=m. Least match n Times and at most m Time . for example ,“o{1,3}” Will match “fooooood” Top three in o.“o{0,1}” Equivalent to “o?”. Please note that there cannot be spaces between commas and two numbers . |
| ? | When the character follows any other qualifier (*,+,?,{
n},{
n,},{
n,m}) In the back , Matching patterns are non greedy . The non greedy pattern matches as few strings as possible , The default greedy pattern matches as many strings as possible . for example , For strings “oooo”,“o+?” Will match a single “o”, and “o+” Will match all “o”. |
| . | Matching elimination “\n” Any single character other than . To match includes “\n” Any character inside , Please use the image “(.|\n)” The pattern of . |
| (pattern) | matching pattern And get the match . The resulting match can be derived from Matches Gather to get , stay VBScript Use in SubMatches aggregate , stay JScript Use... In $0…$9 attribute . To match parenthesis characters , Please use “\(” or “\)”. |
| (?:pattern) | matching pattern But it does not get a match , That is to say, this is a non retrieval match , No storage for later use . This is in use or characters “(|)” It's useful to combine the parts of a pattern . for example “industr(?:y|ies)” It's a comparison “industry|industries” A simpler expression . |
| (?=pattern) | Positive positive preview , In any match pattern Match at the beginning of the string to find the string . This is a non fetch match , in other words , The match does not need to be retrieved for later use . for example ,“Windows(?=95|98|NT|2000)” Can match “Windows2000” Medium “Windows”, But can't match “Windows3.1” Medium “Windows”. Pre check does not consume characters , in other words , After a match happens , Start the search for the next match immediately after the last match , Instead of starting after the character that contains the prefetch . |
| (?!pattern) | Positive negative pre check , In any mismatch pattern Match at the beginning of the string to find the string . This is a non fetch match , in other words , The match does not need to be retrieved for later use . for example “Windows(?!95|98|NT|2000)” Can match “Windows3.1” Medium “Windows”, But can't match “Windows2000” Medium “Windows”. Pre check does not consume characters , in other words , After a match happens , Start the search for the next match immediately after the last match , Instead of starting after the character that contains the prefetch |
| (?<=pattern) | Reverse positive preview , It is similar to positive positive positive pre check , Just in the opposite direction . for example ,“(?<=95|98|NT|2000)Windows” Can match “2000Windows” Medium “Windows”, But can't match “3.1Windows” Medium “Windows”. |
| (?<!pattern) | Reverse negative pre check , It is similar to the positive negative pre check class , Just in the opposite direction . for example “(?<!95|98|NT|2000)Windows” Can match “3.1Windows” Medium “Windows”, But can't match “2000Windows” Medium “Windows”. |
| x|y | matching x or y. for example ,“z|food” Can match “z” or “food”.“(z|f)ood” The match “zood” or “food”. |
| [xyz] | Character set . Matches any of the contained characters . for example ,“[abc]” Can match “plain” Medium “a”. |
| [^xyz] | Negative character set . Match any character not included . for example ,“[^abc]” Can match “plain” Medium “p”. |
| [a-z] | character in range . Matches any character in the specified range . for example ,“[a-z]” Can match “a” To “z” Any lowercase character in the range . |
| [^a-z] | Negative character range . Matches any character that is not in the specified range . for example ,“[^a-z]” Can match anything not in “a” To “z” Any character in the range . |
| \b | Matches a word boundary , That is, the position between the word and the space . for example ,“er\b” Can match “never” Medium “er”, But can't match “verb” Medium “er”. |
| \B | Match non word boundaries .“er\B” Can match “verb” Medium “er”, But can't match “never” Medium “er”. |
| \cx | Match by x Control characters indicated . for example ,\cM Match one Control-M Carriage return .x The value of must be A-Z or a-z One of . otherwise , take c As an original “c” character . |
| \d | Matches a numeric character . Equivalent to [0-9]. |
| \D | Matches a non-numeric character . Equivalent to [^0-9]. |
| \f | Match a page break . Equivalent to \x0c and \cL. |
| \n | Match a line break . Equivalent to \x0a and \cJ. |
| \r | Match a carriage return . Equivalent to \x0d and \cM. |
| \s | Matches any whitespace characters , Including Spaces 、 tabs 、 Page breaks and so on . Equivalent to [ \f\n\r\t\v]. |
| \S | Matches any non-whitespace characters . Equivalent to [^ \f\n\r\t\v]. |
| \t | Match a tab . Equivalent to \x09 and \cI. |
| \v | Match a vertical tab . Equivalent to \x0b and \cK. |
| \w | Match any word character that includes an underline . Equivalent to “[A-Za-z0-9_]”. |
| \W | Match any non word character . Equivalent to “[^A-Za-z0-9_]”. |
| \xn | matching n, among n Is the hexadecimal escape value . The hexadecimal escape value must be two digits long . for example ,“\x41” matching “A”.“\x041” Is equivalent to “\x04&1”. Regular expressions can use ASCII code .. |
| \num | matching num, among num Is a positive integer . Reference to the match obtained . for example ,“(.)\1” Match two consecutive identical characters . |
| \n | Identifies an octal escape value or a backward reference . If \n At least before n Get subexpressions , be n For backward reference . otherwise , If n It's octal (0-7), be n Is an octal escape value . |
| \nm | Identifies an octal escape value or a backward reference . If \nm At least before nm Get subexpressions , be nm For backward reference . If \nm At least before n Get , be n For a following text m Back quote of . If none of the previous conditions are satisfied , if n and m All are octal numbers (0-7), be \nm Will match octal escape value nm. |
| \nml | If n It's octal (0-3), And m and l All are octal numbers (0-7), Then it matches the octal escape value nml. |
| \un | matching n, among n It's a four hexadecimal number Unicode character . for example ,\u00A9 Match copyright symbol (). |
Common regular expressions
| user name | /^[a-z0-9_-]{3,16}$/ |
|---|---|
| password | /^[a-z0-9_-]{6,18}$/ |
| Hexadecimal value | /^#?([a-f0-9]{6}|[a-f0-9]{3})$/ |
| /^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/ /^[a-z\d]+(\.[a-z\d]+)*@([\da-z](-[\da-z])?)+(\.{1,2}[a-z]+)+$/ |
|
| URL | /^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/ |
| IP Address | /((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)/ /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/ |
| HTML label | /^<([a-z]+)([^<]+)*(?:>(.*)<\/\1>|\s+\/>)$/ |
| Delete the code \\ notes | (?<!http:|\S)//.*$ |
| Unicode The range of Chinese characters in the code | /^[\u2E80-\u9FFF]+$/ |
版权声明
本文为[Yunmeng GUIYAO]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210924263604.html
边栏推荐
- 1171: 加密(指针专题)
- 云网融合 — 算力中心 — RoCE/RMDA 与 NVMe/NVMe-oF
- Open3d读写pcd点云文件
- CC00000.CloudJenkins—————————————
- Multithreaded copy set (New 4)
- ARPU, the user of China Mobile, has re entered the rising channel, and the salary of employees has also increased steadily
- 计算器(力扣)
- Penetration practice - dig a school site vulnerability (APP vulnerability)
- Netease blog is going to be closed. My article!
- 极客大挑战 2019 Upload 1
猜你喜欢
随机推荐
Transaction isolation level and mvcc
CC10000.CloudJenkins—————————————
【云驻共创】华为云数据库之数据库原理及应用课程11、数据库系统控制
1164: 字符串加密
模拟实现vector
1151: large integer addition
1147: find subarray
Postman test excel file import and export function
YApi基本使用(2022-04-15)
Open3d读写ply点云文件
Open3d reads and writes PCD point cloud files
Pipy mqtt agent (III) logging
1165: 实数的小数部分(指针专题)
【CVPR 2020】PointASNL :Robust Point Clouds Processing using Nonlocal Neural Networks
Redisson introduction and integration
Multithreaded copy set (New 4)
网格布局--grid
The database has a table in which JSON data is stored in one field. I need to parse this string when this table is updated, and then update the parsed JSON data to another table. What are the good sug
Handler asynchronous message passing mechanism (2) create handler in sub thread
Detailed explanation of native and H5 mixed development
![Kali:sqlmap :[10:39:37] [CRITICAL] unable to connect to the target URL](/img/bf/123e6f5eadb8d502e135a7cff9b120.png)






