Description | Examples | |
. | match any one character | .a.. sales1.xls |
[ ] | define a character set | [ns]a[0-9]\.xls sam.xls na1.xls |
^ | anything but | [ns]a[0-9]\.xls sam.xls na1.xls |
\d \D \w \W | any digit, same as [0-9] any nondigit [^0-9] same as [a-zA-Z0-9_] | \w\d\w\d\w\d M1B4F2 90046 H1H2H2 |
+ | match one or more char | \w+@\w+\.\w+ Send personal email to ben@forta.com. |
* | match 0 or more char | \w+[\w.]*@[\w.]+\.\w+ Hello .ben@forta.com is my email address. |
? | match only 0 or 1 char | https?://[\w./]+ securely use https://www.forta.com/ instead. |
{ } | intervals: {2,4}: min 2, max 4 {3,}: at least 3 | \d{1,2}[-\/]\d{1,2}[-\/]\d{2,4} 4/8/03 10-6-2004 2/2/2 \d+: \$\d{3,}\.\d{2} 1001: $496.80 1002: $1290.69 1003: $26.43 |
*? +? {n,}? | Lazy matching *, +, {n,} are greedy matching | <[Bb]>.*</[Bb]> living in <B>AK</B> and <B>HI</B> <[Bb]>.*?</[Bb]> living in <B>AK</B> and <B>HI</B> |
\b \B | match the start or end of a word, | \bcat\b The cat scattere cap\b captain recap |
( ) | treat as single entity | {2,} Windows 200 (it matches ;;;;) ( ){2,} Windows 200 (\d{1,3}\.){3}\d{1,3} Pinging [12.159.46.200] (19|20)\d{2} DOB: 1967-08-17 |
?= ?<= | look ahead look behind | .+(?=:) http://www.forta.com/ (?<=\$)[0-9.]+ ABC01: $23.45 |
Thursday, December 20, 2007
RegEx basic
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment