App Store購(gòu)買鏈接(¥30 價(jià)格其實(shí)還可以接受网持,請(qǐng)支持正版) | Expressions 官網(wǎng)
特性
- 極簡(jiǎn)化的UI界面;
- 語(yǔ)法高亮顯示匀钧;
- 參考表翎碑;
- 實(shí)時(shí)預(yù)覽;
- 正則表達(dá)式語(yǔ)法庫(kù)提示之斯;
- 組突出顯示日杈;
- 組之間輕松切換(快捷鍵:
cmd+shift+}
orcmd+shift+{
); - 漂亮的全屏視圖;
- 多行模式和注釋佑刷;
- 支持亮暗兩種主題莉擒;
正則表達(dá)式
正則表達(dá)式,又稱規(guī)則表達(dá)式瘫絮。(英語(yǔ):Regular Expression涨冀,在代碼中常簡(jiǎn)寫為 regex、regexp 或 RE)麦萤,計(jì)算機(jī)科學(xué)的一個(gè)概念鹿鳖。它是對(duì)字符串操作的一種邏輯公式。正則表達(dá)式可以檢測(cè)給定的字符串是否符合我們定義的邏輯壮莹,也可以從字符串中獲取我們想要的特定部分翅帜。它可以迅速地用極簡(jiǎn)單的方式達(dá)到字符串的復(fù)雜控制。
正則表通常被用來(lái)檢索命满、替換那些符合某個(gè)模式(規(guī)則)的文本涝滴。
維基百科、百度百科
Basic - 基本語(yǔ)法
Metacharacters - 元字符
表示字符集或特殊字符胶台。
正則表達(dá)式 | 說(shuō)明 | 描述 |
---|---|---|
. | any character | 任意字符 |
^ | beginning of a line | 一行的開始字符 |
$ | end of a line | 一行的末尾字符 |
\ | quotes special characters (* ? + [ ] ( ) { } ^ $ | \ . / ) | 特殊字符的轉(zhuǎn)義符號(hào)(* ? + [ ] ( ) { } ^ $ | \ . / )與括號(hào)中的特殊字符配合使用歼疮,如 \? 、\\
|
\w | word | 所有的文字?jǐn)?shù)字式字符:大小寫字母诈唬、數(shù)字和下劃線韩脏。 同 [a-zA-Z0-9_]
|
\t | horizontal tabulation | 水平制表符 |
\n | new line | 換行符 |
\d | any digit | 任何數(shù)字。 同 [0-9]
|
\s | white space character (\t \n \f \r \p{Z}) | 所有空白字符(\t 制表符 \n 換行 \f 換頁(yè)符 \r 回車 \p{Z} ) |
[...] | match any character (or range of characters) inside the brackets. Range may be e.g. [a-z], [A-Z], [3…5], etc. | 括號(hào)內(nèi)的字符集合讯榕、字符區(qū)間或數(shù)字范圍骤素。 例如: [a-z] 匙睹、[A-Z] 、[3...5]
|
\D | any character that is not a decimal digit | 任何非數(shù)字济竹。 同 [^0-9]
|
\S | non-white space character | 任何非空白字符 |
\W | non-word character | 任何非文字?jǐn)?shù)字式字符痕檬。 同 [^a-zA-Z0-9_]
|
Operators - 運(yùn)算符
運(yùn)算符允許描述一個(gè)表達(dá)式(或子表達(dá)式)應(yīng)如何匹配。
正則表達(dá)式 | 說(shuō)明 | 描述 |
---|---|---|
(...) | groups expression into subexpressions | 將表達(dá)式分組成子表達(dá)式 |
A|B | alternation. Matches A or B | 邏輯運(yùn)算符“或”送浊。 匹配 A 或 B |
^ | negation | 否定表達(dá)式梦谜,如[^0-9] ,表示匹配非數(shù)字 |
* | match 0 or more times | 匹配0次或者多次 |
+ | match 1 or more times | 匹配1次或者多次 |
? | match zero or one times | 匹配0次或者1次 |
{n} | match exactly n times | 精確匹配 n 次 |
{n,} | 至少匹配 n 次 | |
{n,m} | match at least n time and not more than m | 匹配次數(shù)區(qū)間袭景,至少 n 次唁桩,至多 m 次 |
Non-capturing operators -非捕獲運(yùn)算符
正則表達(dá)式 | 說(shuō)明 | 描述 |
---|---|---|
(?#...) | Comment | 注釋 |
(? : ...) | Subexpression must occur but it's not captured in group. | 子表達(dá)式必須發(fā)生,但不會(huì)在組中捕獲耸棒。 |
(? ! ...) | Makes sure that the subexpression does not occur at current position. It's useful to exclude part of expression. | 確保在當(dāng)前位置不會(huì)發(fā)生子表達(dá)式荒澡。 排除部分表達(dá)式很有用。 |
Advanced - 高級(jí)用法
Metacharacters - 元數(shù)據(jù)
正則表達(dá)式 | 說(shuō)明 | 描述 |
---|---|---|
\a | Match a BELL, \u0007 | 匹配響鈴符號(hào)与殃,\u0007
|
\A | Match at the beginning of the input.Differs from ^ in that \A will not match after a new line within the input. | 輸入開始時(shí)匹配单山,與^ 符號(hào)不同,\A 不會(huì)匹配輸入后的新行 |
\b | Match if the current position is a word boundary.Boundaries occur at the transitions between word (\w) and non-word (\W) characters, with combining marks ignored. | 如果當(dāng)前位置是字邊界則匹配幅疼。邊界出現(xiàn)在文字?jǐn)?shù)字式字符(\w )和非文字?jǐn)?shù)字式字符(\W )字符之間的轉(zhuǎn)換處米奸,組合標(biāo)記被忽略。 |
\B | Match if the current position is not a word boundary. | 如果當(dāng)前位置不是文字?jǐn)?shù)字式字符邊界則匹配爽篷。 |
\cX | Match a control-X character. | 匹配一個(gè)control-X字符悴晰。 |
\d | Match any character with the Unicode General Category of Nd (Number, Decimal Digit.) | 匹配任何字符與Unicode通用類別的Nd(數(shù)字,十進(jìn)制數(shù)字)逐工。 |
\D | Match any character that is not a decimal digit. | 匹配任何不是十進(jìn)制數(shù)字的字符铡溪。 |
\e | Match an ESCAPE, \u001B. | 匹配ESCAPE,\u001B 泪喊。 |
\E | Terminates a \Q…\Equoted sequence. | 終止\ Q ... \ E引用的序列佃却。 |
\f | Match a FORM FEED, \u000C. | 匹配FORM FEED,\u000C 窘俺。 |
\G | Match if the current position is at the end of the previous match. | 如果當(dāng)前位置在上一個(gè)匹配結(jié)束時(shí)匹配。 |
\h | Match a Horizontal White Space character. They are characters with Unicode General Category of Space_Separator plus the ASCII tab (\u0009). | 匹配水平白色空格字符复凳。 它們是具有Unicode通用類別Space_Separator和ASCII選項(xiàng)卡(\u0009 )的字符瘤泪。 |
\H | Match a non-Horizontal White Space character. | 匹配非水平白色空格字符。 |
\k | Named Capture Back Reference. | 命名捕獲返回參考育八。 |
\n | Match a line feed, \u000A. | 匹配換行符 \u000A 对途。 |
\N{unicode} | Match the named character. | 匹配命名的字符。 |
\p{unicode} | Match any character with the specified Unicode Property. | 與指定的Unicode屬性匹配任何字符髓棋。 |
\P{unicode} | Match any character not having the specified Unicode Property. | 匹配任何不具有指定Unicode屬性的字符实檀。 |
\Q | Quotes all following characters until \E. | 引用所有以下字符直到\ E惶洲。 |
\r | Match a carriage return, \u000D. | 匹配回車,\ u000D膳犹。 |
\R | Match a new line character, or the sequence CR LF. | 匹配新的行字符或序列CR LF恬吕。 |
\s | Match a white space character. White space is defined as [\t\n\f\r\p{Z}]. | 匹配一個(gè)空白字符。 空格被定義為 [\t \n \f \r \p{Z}] 须床。 |
\S | Match a non-white space character. | |
\t | Match a horizontal tabulation, \u0009. | 匹配水平制表符铐料,\u0009 。 |
\uhhhh | Match the character with the hex value hhhh. | 匹配十六進(jìn)制字符hhhh豺旬。 |
\uhhhhhhh | Match the character with the hex value hhhhhhhh.Exactly eight hex digits must be provided, even though the largest Unicode code point is \U0010ffff. | 匹配十六進(jìn)制字符hhhhhhhh钠惩。必須提供 8 位十六進(jìn)制數(shù)字,即使最大的Unicode代碼點(diǎn)是 \U0010ffff 族阅。 |
\v | Match a new line character. | 匹配一個(gè)新的行字符篓跛。 |
\V | Match a non-new line character. | |
\w | Match a word character. | 匹配一個(gè)字符 |
\W | Match a non-word character. | |
\x{hhhh} | Match the character with hex value hhhh.From one to six hex digits may be supplied. | 匹配十六進(jìn)制字符hhhh√沟叮可提供1到6個(gè)十六進(jìn)制數(shù)字愧沟。 |
\xhh | Match the character with two digit hex value hh | 匹配兩位十六進(jìn)制字符hh |
\X | Match a Grapheme Cluster . | 匹配一個(gè)大寫字母集 |
\Z | Match if the current position is at the end of input, but before the final line terminator, if one exists. | 如果當(dāng)前位置在輸入結(jié)尾,但在最后一行終止符之前求泰,如果存在央渣,則進(jìn)行匹配。 |
\z | Match if the current position is at the end of input. | 如果當(dāng)前位置在輸入結(jié)束時(shí)匹配渴频。 |
\n | Back Reference. Match whatever the nth capturing group matched. n must be a number > 1 and < total number of capture groups in the pattern. | 返回參考芽丹。 匹配任何第n個(gè)捕獲組匹配。 n必須是數(shù)字> 1和<模式中捕獲組的總數(shù)卜朗。 |
\0ooo | Match an Octal character. 'ooo' is from one to three octal digits. 0377 is the largest allowed Octal character. The leading zero is required; it distinguishes Octal constants from back references. | 匹配八進(jìn)制字符 “ooo”是從一到三個(gè)八進(jìn)制數(shù)字拔第。 0377是允許的最大八進(jìn)制字符。 領(lǐng)先的零是必需的; 它將八進(jìn)制常量與反向引用區(qū)分開來(lái)场钉。 |
[...] | Match any one character from the set. | 匹配集合中的任何一個(gè)字符蚊俺。 |
. | Match any character. | |
^ | Match at the beginning of a line. | |
$ | Match at the end of a line. | |
\ | Quotes the following character. Characters that must be quoted to be treated as literals are * ? + [ ( ) { } ^ $ | \ . | 引用以下字符。必須引用被視為文字的字符是* 逛万?+ [(){} ^ $ | \
|
\ | Quotes the following character. Characters that must be quoted to be treated as literals are [ ] \ | 引用以下字符 ,必須引用被視為文字的字符是[] \ |
Operators - 運(yùn)算符
| | Alternation. A|B matches either A or B. | 或者 |
---|---|---|
* | Match 0 or more times. Match as many times as possible. | 匹配 0 次以上泳猬。 匹配盡可能多的次數(shù)。 |
+ | Match 1 or more times. Match as many times as possible. | 匹配 1 次以上宇植。 匹配盡可能多的次數(shù)得封。 |
? | Match zero or one times. Prefer one. | 匹配0次或1次指郁。 偏向于1次 |
{n} | Match exactly n times | 匹配 n 次 |
{n,} | Match at least n times. Match as many times as possible. | 匹配至少 n 次 |
{n,m} | Match between n and m times. Match as many times as possible, but not more than m. | 匹配 n~m 次 |
*? | Match 0 or more times. Match as few times as possible. | 加后綴 ? 表示非貪婪匹配(匹配盡可能少的字符) |
+? | Match 1 or more times.Match as few times as possible. | |
?? | Match zero or one times. Prefer zero. | |
{n}? | Match exactly n times | |
{n,}? | Match at least n time§s, but no more than required for an overall pattern match | |
{n,m}? | Match between n and m times. Match as few times as possible, but not less than n. | |
*+ | Match 0 or more times. Match as many times as possible when first encountered, do not retry with fewer even if overall match fails (Possessive Match) | 匹配0次以上忙上。 在第一次遇到時(shí),盡可能多地匹配闲坎,即使整體匹配失斠咧唷(Possessive Match)也不要重試茬斧, |
++ | Match 1 or more times. Possessive match. | |
?+ | Match zero or one times. Possessive match. | |
{n}+ | Match exactly n times | |
{n,}+ | Match at least n times. Possessive Match. | |
{n,m}+ | Match between n and m times. Possessive Match. | |
(...) | Capturing parentheses. Range of input that matched the parenthesized subexpression is available after the match. | |
(? : ...) | Non-capturing parentheses. Groups the included pattern, but does not provide capturing of matching text. Somewhat more efficient than capturing parentheses. | 非捕獲括號(hào)。 對(duì)包含的模式進(jìn)行分組梗逮,但不提供匹配文本的捕獲项秉。 比捕捉括號(hào)更有效率。 |
(? > ...) | Atomic-match parentheses. First match of the parenthesized subexpression is the only one tried; if it does not lead to an overall pattern match, back up the search for a match to a position before the "(?>" | |
(?#...) | Free-format comment (?# comment ). | |
(?=...) | Look-ahead assertion. True if the parenthesized pattern matches at the current input position, but does not advance the input position. | |
(?!...) | Negative look-ahead assertion. True if the parenthesized pattern does not match at the current input position. Does not advance the input position. | |
(?<=...) | Look-behind assertion. True if the parenthesized pattern matches text preceding the current input position, with the last character of the match being the input character just before the current position. Does not alter the input position. The length of possible strings matched by the look-behind pattern must not be unbounded (no * or + operators.) | |
(?...) | Negative Look-behind assertion. True if the parenthesized pattern does not match text preceding the current input position, with the last character of the match being the input character just before the current position. Does not alter the input position. The length of possible strings matched by the look-behind pattern must not be unbounded (no * or + operators.) | |
(?...) | Named capture group. The are literal - they appear in the pattern. | |
(?ismwx-ismwx:…) | Flag settings. Evaluate the parenthesized expression with the specified flags enabled or -disabled. | |
(?ismwx-ismwx) | Flag settings. Change the flag settings. Changes apply to the portion of the pattern following the setting. For example, (?i) changes to a case insensitive match. |
Set Expressions - 設(shè)置表達(dá)式
正則表達(dá)式 | 說(shuō)明 | 描述 |
---|---|---|
[abc] | Match any of the characters a, b or c | |
[^abc] | Negation - match any character except a, b or c | |
[A-M] | Range - match any character from A to M. The characters to include are determined by Unicode code point ordering. | |
[\u0000-\U0010ffff] | Range - match all characters. |
Flags
正則表達(dá)式 | 說(shuō)明 | 描述 |
---|---|---|
i | If set, matching will take place in a case-insensitive manner. | |
x | If set, allow use of white space and #comments within patterns | |
s | If set, a "." in a pattern will match a line terminator in the input text. By default, it will not. Note that a carriage-return / line-feed pair in text behave as a single line terminator, and will match a single "." in a RE pattern. | |
m | Control the behavior of ^ and $ in a pattern. By default these will only match at the start and end, respectively, of the input text. If this flag is set, ^ and $
|
多行匹配(?m)
|
will also match at the start and end of each line within the input text. | Controls the behavior of \b in a pattern. If set, word boundaries are found according to the definitions of word found in Unicode UAX 29, Text Boundaries. By default, word boundaries are identified by means of a simple classification of characters as either “word” or “non-word”, which approximates traditional regular expression behavior. The results obtained with the two options can be quite different in runs of spaces and other non-word characters. |
貪婪匹配和非貪婪匹配的區(qū)分
- 貪婪匹配:匹配盡可能多的字符库糠。也就是說(shuō)伙狐,正則表達(dá)式總是尋找最大的匹配,而不是最小的瞬欧,這是故意設(shè)計(jì)的贷屎。
- 非貪婪匹配:匹配盡可能少的字符。
貪婪量詞 | 非貪婪量詞 | |
---|---|---|
* | *? | |
+ | +? | |
? | ?? | |
{n} | {n}? | |
{n,} | {n,}? | |
{n,m} | {n,m}? |
示例
正則表達(dá)式:a.*z
默認(rèn)是貪婪匹配艘虎,正則表達(dá)式引擎會(huì)盡可能地匹配滿足條件的最大區(qū)間唉侄。
正則表達(dá)式:a.*?z
在貪婪量詞后面加?
即可實(shí)現(xiàn)非貪婪匹配。
常用正則表達(dá)式
一野建、校驗(yàn)數(shù)字的表達(dá)式
1 數(shù)字:^[0-9]*$
2 n位的數(shù)字:^\d{n}$
3 至少n位的數(shù)字:^\d{n,}$
4 m-n位的數(shù)字:^\d{m,n}$
5 零和非零開頭的數(shù)字:^(0|[1-9][0-9]*)$
6 非零開頭的最多帶兩位小數(shù)的數(shù)字:^([1-9][0-9]*)+(.[0-9]{1,2})?$
7 帶1-2位小數(shù)的正數(shù)或負(fù)數(shù):^(\-)?\d+(\.\d{1,2})?$
8 正數(shù)属划、負(fù)數(shù)、和小數(shù):^(\-|\+)?\d+(\.\d+)?$
9 有兩位小數(shù)的正實(shí)數(shù):^[0-9]+(.[0-9]{2})?$
10 有1~3位小數(shù)的正實(shí)數(shù):^[0-9]+(.[0-9]{1,3})?$
11 非零的正整數(shù):^[1-9]\d*$ 或 ^([1-9][0-9]*){1,3}$ 或 ^\+?[1-9][0-9]*$
12 非零的負(fù)整數(shù):^\-[1-9][]0-9"*$ 或 ^-[1-9]\d*$
13 非負(fù)整數(shù):^\d+$ 或 ^[1-9]\d*|0$
14 非正整數(shù):^-[1-9]\d*|0$ 或 ^((-\d+)|(0+))$
15 非負(fù)浮點(diǎn)數(shù):^\d+(\.\d+)?$ 或 ^[1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0$
16 非正浮點(diǎn)數(shù):^((-\d+(\.\d+)?)|(0+(\.0+)?))$ 或 ^(-([1-9]\d*\.\d*|0\.\d*[1-9]\d*))|0?\.0+|0$
17 正浮點(diǎn)數(shù):^[1-9]\d*\.\d*|0\.\d*[1-9]\d*$ 或 ^(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*))$
18 負(fù)浮點(diǎn)數(shù):^-([1-9]\d*\.\d*|0\.\d*[1-9]\d*)$ 或 ^(-(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*)))$
19 浮點(diǎn)數(shù):^(-?\d+)(\.\d+)?$ 或 ^-?([1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0)$
二候生、校驗(yàn)字符的表達(dá)式
1 漢字:^[\u4e00-\u9fa5]{0,}$
2 英文和數(shù)字:^[A-Za-z0-9]+$ 或 ^[A-Za-z0-9]{4,40}$
3 長(zhǎng)度為3-20的所有字符:^.{3,20}$
4 由26個(gè)英文字母組成的字符串:^[A-Za-z]+$
5 由26個(gè)大寫英文字母組成的字符串:^[A-Z]+$
6 由26個(gè)小寫英文字母組成的字符串:^[a-z]+$
7 由數(shù)字和26個(gè)英文字母組成的字符串:^[A-Za-z0-9]+$
8 由數(shù)字同眯、26個(gè)英文字母或者下劃線組成的字符串:^\w+$ 或 ^\w{3,20}$
9 中文、英文唯鸭、數(shù)字包括下劃線:^[\u4E00-\u9FA5A-Za-z0-9_]+$
10 中文须蜗、英文、數(shù)字但不包括下劃線等符號(hào):^[\u4E00-\u9FA5A-Za-z0-9]+$ 或 ^[\u4E00-\u9FA5A-Za-z0-9]{2,20}$
11 可以輸入含有^%&',;=?$\"等字符:[^%&',;=?$\x22]+
12 禁止輸入含有~的字符:[^~\x22]+
三目溉、特殊需求表達(dá)式
1 Email地址:^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$
2 域名:[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(/.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+/.?
3 InternetURL:[a-zA-z]+://[^\s]* 或 ^http://([\w-]+\.)+[\w-]+(/[\w-./?%&=]*)?$
4 手機(jī)號(hào)碼:^(13[0-9]|14[0-9]|15[0-9]|166|17[0-9]|18[0-9]|19[8|9])\d{8}$
5 電話號(hào)碼("XXX-XXXXXXX"明肮、"XXXX-XXXXXXXX"、"XXX-XXXXXXX"缭付、"XXX-XXXXXXXX"柿估、"XXXXXXX"和"XXXXXXXX):^(\(\d{3,4}-)|\d{3.4}-)?\d{7,8}$
6 國(guó)內(nèi)電話號(hào)碼(0511-4405222、021-87888822):\d{3}-\d{8}|\d{4}-\d{7}
7 18位身份證號(hào)碼(數(shù)字陷猫、字母x結(jié)尾):^((\d{18})|([0-9x]{18})|([0-9X]{18}))$
8 帳號(hào)是否合法(字母開頭秫舌,允許5-16字節(jié),允許字母數(shù)字下劃線):^[a-zA-Z][a-zA-Z0-9_]{4,15}$
9 密碼(以字母開頭绣檬,長(zhǎng)度在6~18之間舅巷,只能包含字母、數(shù)字和下劃線):^[a-zA-Z]\w{5,17}$
10 ??強(qiáng)密碼(必須包含大小寫字母和數(shù)字的組合河咽,不能使用特殊字符,長(zhǎng)度在8-10之間):^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,10}$
11 日期格式:^\d{4}-\d{1,2}-\d{1,2}
12 一年的12個(gè)月(01~09和1~12):^(0?[1-9]|1[0-2])$
13 一個(gè)月的31天(01~09和1~31):^((0?[1-9])|((1|2)[0-9])|30|31)$
14 錢的輸入格式:
15 1.有四種錢的表示形式我們可以接受:"10000.00" 和 "10,000.00", 和沒有 "分" 的 "10000" 和 "10,000":^[1-9][0-9]*$
16 2.這表示任意一個(gè)不以0開頭的數(shù)字,但是,這也意味著一個(gè)字符"0"不通過(guò),所以我們采用下面的形式:^(0|[1-9][0-9]*)$
17 3.一個(gè)0或者一個(gè)不以0開頭的數(shù)字.我們還可以允許開頭有一個(gè)負(fù)號(hào):^(0|-?[1-9][0-9]*)$
18 4.這表示一個(gè)0或者一個(gè)可能為負(fù)的開頭不為0的數(shù)字.讓用戶以0開頭好了.把負(fù)號(hào)的也去掉,因?yàn)殄X總不能是負(fù)的吧.下面我們要加的是說(shuō)明可能的小數(shù)部分:^[0-9]+(.[0-9]+)?$
19 5.必須說(shuō)明的是,小數(shù)點(diǎn)后面至少應(yīng)該有1位數(shù),所以"10."是不通過(guò)的,但是 "10" 和 "10.2" 是通過(guò)的:^[0-9]+(.[0-9]{2})?$
20 6.這樣我們規(guī)定小數(shù)點(diǎn)后面必須有兩位,如果你認(rèn)為太苛刻了,可以這樣:^[0-9]+(.[0-9]{1,2})?$
21 7.這樣就允許用戶只寫一位小數(shù).下面我們?cè)摽紤]數(shù)字中的逗號(hào)了,我們可以這樣:^[0-9]{1,3}(,[0-9]{3})*(.[0-9]{1,2})?$
22 8.1到3個(gè)數(shù)字,后面跟著任意個(gè) 逗號(hào)+3個(gè)數(shù)字,逗號(hào)成為可選,而不是必須:^([0-9]+|[0-9]{1,3}(,[0-9]{3})*)(.[0-9]{1,2})?$
23 備注:這就是最終結(jié)果了,別忘了"+"可以用"*"替代如果你覺得空字符串也可以接受的話(奇怪,為什么?)最后,別忘了在用函數(shù)時(shí)去掉去掉那個(gè)反斜杠,一般的錯(cuò)誤都在這里
24 xml文件:^([a-zA-Z]+-?)+[a-zA-Z0-9]+\\.[x|X][m|M][l|L]$
25 中文字符的正則表達(dá)式:[\u4e00-\u9fa5]
26 雙字節(jié)字符:[^\x00-\xff] (包括漢字在內(nèi)赋元,可以用來(lái)計(jì)算字符串的長(zhǎng)度(一個(gè)雙字節(jié)字符長(zhǎng)度計(jì)2忘蟹,ASCII字符計(jì)1))
27 空白行的正則表達(dá)式:\n\s*\r (可以用來(lái)刪除空白行)
28 HTML標(biāo)記的正則表達(dá)式:<(\S*?)[^>]*>.*?</\1>|<.*? /> (網(wǎng)上流傳的版本太糟糕飒房,上面這個(gè)也僅僅能部分首有,對(duì)于復(fù)雜的嵌套標(biāo)記依舊無(wú)能為力)
29 首尾空白字符的正則表達(dá)式:^\s*|\s*$或(^\s*)|(\s*$) (可以用來(lái)刪除行首行尾的空白字符(包括空格惕蹄、制表符驶鹉、換頁(yè)符等等)罪针,非常有用的表達(dá)式)
30 騰訊QQ號(hào):[1-9][0-9]{4,} (騰訊QQ號(hào)從10000開始)
31 中國(guó)郵政編碼:[1-9]\d{5}(?!\d) (中國(guó)郵政編碼為6位數(shù)字)
32 IP地址:\d+\.\d+\.\d+\.\d+ (提取IP地址時(shí)有用)
33 IP地址:((?:(?:25[0-5]|2[0-4]\\d|[01]?\\d?\\d)\\.){3}(?:25[0-5]|2[0-4]\\d|[01]?\\d?\\d)) (由@飛龍三少 提供,感謝共享)
?? 6到20位的字符: ^[a-zA-Z0-9~!@#%&*.,_?/\\\\]{6,20}$
?? 6到20位的字符撵颊,不能是純數(shù)字:^(?=.*[a-zA-Z~!@#%&*.,_?/\\\\])(?=.*[a-zA-Z0-9~!@#%&*.,_?/\\\\]).{6,20}$
參考
- 完整的正則表達(dá)式文檔:ICU User Guide
- Regular Expression Language - Quick Reference
- 《系統(tǒng)地學(xué)習(xí)正則表達(dá)式(一):基礎(chǔ)篇》 @iOS_小松哥
- 《系統(tǒng)地學(xué)習(xí)正則表達(dá)式(二):進(jìn)階篇》 @iOS_小松哥
- 最全的常用正則表達(dá)式大全——包括校驗(yàn)數(shù)字贞岭、字符又憨、一些特殊的需求等等
- iOS 正則表達(dá)式語(yǔ)法全集
- 密碼強(qiáng)度正則表達(dá)式 – 必須包含大寫字母袜炕,小寫字母和數(shù)字锰扶,至少 8 個(gè)字符等