Regular Expressions: Difference between revisions
Jump to navigation
Jump to search
(Added "Random Examples") |
(Re-arranged page) |
||
Line 1: | Line 1: | ||
== | == Examples == | ||
=== Basic === | |||
{|cellpadding="2" cellspacing="0" border="1" | {|cellpadding="2" cellspacing="0" border="1" | ||
|- style="background-color:#bbddff;" | |- style="background-color:#bbddff;" | ||
! Matches !! Expression | ! Matches !! Expression | ||
|- | |- | ||
| '' | | Anything containing ''text'' | ||
| <code><nowiki> | | <code><nowiki> .*text* </nowiki></code> | ||
|} | |} | ||
== Random == | |||
== Random | |||
* '''Filename''' | * '''Filename''' | ||
** <code> \d{4}-[A-Za-z]{3}-Week\d{1}.log </code> | ** <code> \d{4}-[A-Za-z]{3}-Week\d{1}.log </code> | ||
Line 19: | Line 16: | ||
*** 2009-Dec-Week2.log | *** 2009-Dec-Week2.log | ||
*** 1234-aBc-Week0.log | *** 1234-aBc-Week0.log | ||
== Useful RegEx == | |||
{|cellpadding="2" cellspacing="0" border="1" | |||
|- style="background-color:#bbddff;" | |||
! Matches !! Expression | |||
|- | |||
| '''IP Address''' | |||
| <code><nowiki> ^\b((25[0-5]|2[0-4]\d|[01]\d\d|\d?\d)\.){3}(25[0-5]|2[0-4]\d|[01]\d\d|\d?\d)\b </nowiki></code> | |||
|- | |||
| '''Hostname''' (no domain) | |||
| <code><nowiki> \A(\w|-)+ </nowiki></code> | |||
|- | |||
| '''Email address''' | |||
| <code><nowiki> \b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b </nowiki></code> | |||
|} |
Revision as of 10:36, 12 August 2010
Examples
Basic
Matches | Expression |
---|---|
Anything containing text | .*text*
|
Random
- Filename
\d{4}-[A-Za-z]{3}-Week\d{1}.log
- Example matches...
- 2010-Feb-Week4.log
- 2009-Dec-Week2.log
- 1234-aBc-Week0.log
Useful RegEx
Matches | Expression |
---|---|
IP Address | ^\b((25[0-5]|2[0-4]\d|[01]\d\d|\d?\d)\.){3}(25[0-5]|2[0-4]\d|[01]\d\d|\d?\d)\b
|
Hostname (no domain) | \A(\w|-)+
|
Email address | \b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b
|