| Sponsored link: |
|
Windows grep software to search (and replace) through files and folders on your PC and network |
| Regular Expressions | ||||
|---|---|---|---|---|
| Function | Regular Expression | Will match | Remarks | |
| Simple date | \b([0-9]{1,2}[-/][0-9]{1,2}[-/]([0-9]{2})?[0-9]{2})\b |
Any date | Will match 99/99/9999 or 00-00-00 | |
| Date (MM/DD/YYYY) | \b((0?[1-9]|1[0-2])/(0?[1-9]|[12][0-9]|3[01])/[12][0-9]{3})\b |
Date in current or previous millenium | Will match 2/31/2010 | |
| Date (DD-MM-YYYY) | \b((0?[1-9]|[12][0-9]|3[01])-(0?[1-9]|1[0-2])-[12][0-9]{3})\b |
Date in current or previous millenium | Will match 31-2-2010 | |
| Simple time | \b([0-9]{1,2}:[0-9]{2}(:[0-9]{2}(\.[0-9]+)?)?)\b |
Any time | Will match 99:99:99.999 | |
| Time (24h) | \b(([01]?[0-9]|2[0-3]):[0-5][0-9](:[0-5][0-9](\.[0-9]+)?)?)\b |
True time | Will only match valid times in 24h notation, with seconds and fraction of seconds optional | |
| Time (AM/PM) | \b((0?[0-9]|1[0-2]):[0-5][0-9](:[0-5][0-9](\.[0-9]+)?)? ?([AaPp][Mm]?)?)\b |
True time | Will only match valid times in AM/PM notation, with seconds, fraction of seconds and AM/PM/A/P optional and case insensitive | |
| E-mail adrress | \b([\w-\.]+\@([\w-]+\.)+[\da-zA-Z]{2,4})\b |
Valid e-mail address | Will also find a match even in invalid numerical top level domains; when an e-mail address is valid, it doesn't necessarily mean it exists. | |
| Simple HTML tag | (<[ˆ>]+>) |
Any tag in HTML code | Will fail on <img src="fastforward.gif" alt=">>"> | |
| HTML tag with embedded text | (<[ˆ>]+>([ˆ<]+<\/[ˆ>]+>)?) |
Single tag only or "tag set" including attributes | Will also fail on <img src="fastforward.gif" alt=">>"> and on nested HTML tags, e.g. <b><i>text</i></b> | |
| HTML tag with embedded text | (<[ˆ>\"]+([ˆ\">]+=\"[ˆ\"]*\" *)*>([ˆ<]+<\/[ˆ>]+>)?) |
Single tag only or "tag set" including attributes | Will fail on nested tags, e.g. <b><i>text</i></b> and doesn't detect incorrect tag sets, e.g. <b>text</i> | |
| HTML tag with embedded text | (<([ˆ\/\s>\"])+(\s+[ˆ\">]+=\"[ˆ\"]*\"\s*)*>(.+<\/\2>)?) |
Single tag only or "tag set" including attributes | Does not detect improperly nested tags, e.g. <b><i>text</b></i> | |
| Simple IP address | \b(([0-9]{1,3}\.){3}[0-9]{1,3})\b |
Any IP address | Will match 999.999.999.999 | |
| IP address | \b(([0-2]?[0-9]{1,2}\.){3}[0-2]?[0-9]{1,2})\b |
Any IP address | Will still match 299.299.299.299 | |
| True IP address | \b((([01]?[0-9]{1,2}|2([0-4][0-9]|5[0-5]))\.){3}([01]?[0-9]{1,2}|2([0-4][0-9]|5[0-5])))\b |
True IP address | Will only match valid IP addresses, does accept leading zeroes | |
| page last uploaded: 4 March 2011, 12:52 |