解釋
| Regex | Explanation | 
| + | >= 1 — 匹配前面的子運算式,出現了1次以上 | 
| ? | = 0 / 1 — 匹配前面的子運算式,出現了 0 次或 1 次 | 
| * | > 0 — 匹配前面的子運算式,出現了 0 次以上 | 
| {} | Exactly the specified number of occurrences | 
| {n} | 例: {2}出現了2次 | 
| {n,} | 例: {2,}出現了2次以上 | 
| {,m} | 例: {,10}出現了10次以下 | 
| {n,m} | n<=m  ,例: {2,5}出現了2-5次 | 
| Regex | Explanation | 
| . | 任何單個字元,除了 \n。 Find a single character, except newline or line terminator | 
| [.\n] | 任何單個字元,包括 \n。 | 
| ^ | 字串開頭 Starts with | 
| $ | 字串結尾 Ends with | 
| | | OR | 
| Regex | Explanation | 
| \ | Signals a special sequence (can also be used to escape special characters) | 
| \. | 即是 .,因為如果直接寫.會被當成regex「任意字元」的意思 | 
| \+ | 即是 +,因為如果直接寫+會被當成regex「出現1次以上」的意思 | 
| \? | 即是 ?,因為如果直接寫?會被當成regex「出現 0 次或 1 次」的意思 | 
| \* | 即是 *,因為如果直接寫*會被當成regex「出現 0 次以上」的意思 | 
| \( | 即是 ( | 
| \) | 即是 ) | 
| \[ | 即是 [ | 
| \] | 即是 ] | 
| \\ | 即是 \ | 
| \a | 匹配單個字元 a,含字母 “a” 的字串,a-z 0-9 也同樣道理用法 | 
| Regex | Explanation | 
| \d | 匹配一個數位字元,等同 [0-9]Find a digit | 
| \D | 匹配一個非數位字元,等同 [^0-9]Find a non-digit character | 
| \n | 換行  New line | 
| \r | 回車 Enter carriage return | 
| \t | Tab | 
| \s | 空白、換行、tab。等同 [\f\n\r\t\v]Find a whitespace character | 
| \S | 非空白、換行、tab。等同 [^\f\n\r\t\v]Find a non-whitespace character | 
| \w | 數字、字母、底線,等同 [A-Za-z0-9_]Find a word character | 
| \W | 非數字、字母、底線。等同 [^A-Za-z0-9_]Find a non-word character | 
| Regex | Explanation | 
| () | Capture and group | 
| [] | include things mentioned inside the bracket  (A set of characters) | 
| [^] | NOT include things mentioned inside the bracket | 
例子
| Regex | Explanation | Example | 
| [0123456789]+ | 所有數字(整數) | 721831 | 
| [0-9]+ | 上面可簡化成這樣寫 | 721831 | 
| [\d]+ | 也可寫成這樣, \d等同[0-9] | 721831 | 
| [0-9]+\.[0-9]+ | 有小數點的實數 | 53.1456 | 
| [A-Za-z]+ | 英文(大小寫組合皆可) | HelloWorld | 
| [A-Z]+ | 英文(大寫字母only) | HELLOWORLD | 
| [a-z]+ | 英文(小寫字母only) | helloworld | 
| [a-zA-Z0-9_]+@[a-zA-Z0-9\._]+ | Email address | abc@abc.cc | 
| [a-zA-Z0-9_]+@gmail\.com$ | Gmail address | abc@gmail.com | 
| (http|https)://[a-zA-Z0-9\./_]+ | URL | http://hello.com/index/ | 
參考
如果您喜歡我的文章,歡迎幫我在下面按5下讚!感謝您的鼓勵和支持!
版權聲明: 本博客所有文章除特別聲明外,均採用 CC BY-NC-SA 4.0 許可協議。歡迎「部份引用」與介紹(如要全文轉貼請先留言詢問),轉載引用請註明來源 ouoholly 的倉庫,謝謝!