ð° Regular Expressions
Various useful tools and resources for working with regular expressions.
ðĄ Tipsâ
- Think about you want to "match" or "search"
- For matching, use
^
and$
to match the beginning and end of the string- Be careful with multi-line strings
- Different tools may have different syntax
Charactersâ
Character | RegEx | Notes |
---|---|---|
Lowercase letter | [a-z] | |
Uppercase letter | [A-Z] | |
Letter | [a-zA-Z] | |
Digit | \d | Equal to [0-9] |
Non-digit | \D | |
Whitespace | \s | Could be space, tab, etc. |
Non-whitespace | \S | |
Word character | \w | Equal to [a-zA-Z0-9_] |
Non-word | \W | |
Word boundary | \b | |
Non-boundary | \B |
Quantifiersâ
note
In possessive match mode, the regex engine will not backtrack to find a match. This is useful when you know that there is only one possible match. This can be more efficient than greedy or reluctant matching, but more prone to not finding a match.
Quantifiers | RegEx | Notes |
---|---|---|
More or 0 | * | Greedy Match (Prefer more) |
More or 1 | + | Greedy Match (Prefer more) |
1 or 0 | ? | Greedy Match (Prefer one) |
0 or more | *? | Reluctant Match (Prefer 0) |
1 or more | +? | Reluctant Match (Prefer 1) |
0 or 1 | ?? | Reluctant Match (Prefer 0) |
0 or more | *+ | Possessive Match |
1 or more | ++ | Possessive Match |
1 or 0 | ?+ | Possessive Match |
Exactly n | {n} , {n}+ , {n}? | |
At least n | {n,} | Greedy Match (Prefer more) |
Between n and m | {n,m} | Greedy Match (Prefer more) |
At least n | {n,}? | Reluctant Match (Prefer less) |
Between n and m | {n,m}? | Reluctant Match (Prefer less) |
At least n | {n,}+ | Possessive Match |
Between n and m | {n,m}+ | Possessive Match |
Toolsâ
Snippetsâ
Emailâ
TODO
URLâ
TODO
Private IP Address1â
Start | End | CIDR |
---|---|---|
127.0.0.0 | 127.255.255.255 | 127.0.0.0/8 |
10.0.0.0 | 10.255.255.255 | 10.0.0.0/8 |
172.16.0.0 | 172. 31.255.255 | 172.16.0.0/12 |
192.168.0.0 | 192.168.255.255 | 192.168.0.0/16 |
(^127\.)|
(^10\.)|
(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|
(^192\.168\.)
Base64 encoded stringâ
^[a-zA-Z0-9+/]*={0,2}$
Semantic Versionâ
^(\d+)\.(\d+)\.(\d+)$
Chinese Charactersâ
[\u4e00-\u9fa5]
ðđðž Taiwan Addressâ
This is a WIP, might not be perfect.
^[\u4e00-\u9fa5]+?(įļĢ|åļ)[\u4e00-\u9fa5]+?(é|éŪ|åļ|å)[\u4e00-\u9fa5]+?(č·Ŋ|čĄ|åĪ§é)([\u4e00-\u9fa5]+?æŪĩ)?(\d+?å··)?(\d+?åž)?[\d\-ã]+?č(.+?æĢ)?((B?[\d]+?|G|L)æĻ)?(äđ\d+?)?$
ðđðž Taiwan Address with Villageâ
^[\u4e00-\u9fa5]+?(įļĢ|åļ)[\u4e00-\u9fa5]+?(é|éŪ|åļ|å)([\u4e00-\u9fa5]+?(æ|é))?(\d+?é°)?[\u4e00-\u9fa5]+?(č·Ŋ|čĄ|åĪ§é)([\u4e00-\u9fa5]+?æŪĩ)?(\d+?å··)?(\d+?åž)?[\d\-ã]+?č(.+?æĢ)?((B?[\d]+?|G|L)æĻ)?(äđ\d+?)?$