Regular Expressions
Regular expressions and used in [[Perl]], [[Apache Rewrite]], [[Vim]] among many other uses.
{|
| align=”center” style=”background:#f0f0f0;”|’'’Regex’’’
| align=”center” style=”background:#f0f0f0;”|’'’Meaning’’’
|-
| .|| Any single character except a newline
|-
| ^|| The beginning of the line or string
|-
| $|| The end of the line or string
|-
| || Zero or more of the last character
|-
| +|| One or more of the last character
|-
| ?|| Zero or one of the last character
|-
| (ben\.)?goodacre.name|| ben.goodacre.name or goodacre.name
|-
| t.e|| t followed by any 1 single character followed by e. This will match the , tre , tle , but not te or tale
|-
| ^f|| f at the beginning of a line
|-
| ^ftp|| ftp at the beginning of a line
|-
| e$|| e at the end of a line
|-
| und|| un followed by zero or more d characters. This will match un , und , undd , unddd etc.
|-
| .*|| Any string without a newline. This is because the . matches anything except a newline and the * means zero or more of these.
|-
| ^$|| A line with nothing in it.
|-
| [qjk]||Either q or j or k
|-
| [^qjk]||Neither q nor j nor k
|-
| [a-z]||Anything from a to z inclusive
|-
| [^a-z]||No lower case letters
|-
| [a-zA-Z]||Any letter
|-
| [a-z]+||Any non-zero sequence of lower case letters
|-
| [^qjk]+ ||Any non-zero sequence that does not contain a q nor j nor k.
|-
| jelly
||A newline
|-
| \ ||A tab
|-
| \w||Any alphanumeric (word) character.
|-
| ||The same as [a-zA-Z0-9_]
|-
| \W||Any non-word character.
|-
| ||The same as [^a-zA-Z0-9_]
|-
| \d||Any digit. The same as [0-9]
|-
| \D||Any non-digit. The same as [^0-9]
|-
| \s||Any whitespace character: space, tab, newline, etc
|-
| \S||Any non-whitespace character
|-
| \b||A word boundary, outside [] only
|-
| \B||No word boundary
|}
===Match a date yyyy-mm-dd===
\\d{4}-\\d{2}-\\d{2}
Needs some work, will also match 9999-99-99 . ===Time hh:mm:ss===
\\d{2}:\\d{2}:\\d{2}
Needs some work, will also match 99:99:99 . ===Mac address=== With -‘s or :’s
[0-9a-f][0-9a-f][:-][0-9a-f][0-9a-f][:-][0-9a-f][0-9a-f][:-][0-9a-f][0-9a-f][:-][0-9a-f][0-9a-f][:-][0-9a-f][0-9a-f]
===IP adress===
^([0-9]|[1-9][0-9]|1([0-9][0-9])|2([0-4][0-9]|5[0-5]))\\.([0-9]|[1-9][0-9]|1([0-9][0-9])|2([0-4][0-9]|5[0-5]))\\.([0-9]|[1-9][0-9]|1([0-9][0-9])|2([0-4][0-9]|5[0-5]))\\.([0-9]|[1-9][0-9]|1([0-9][0-9])|2([0-4][0-9]|5[0-5]))$
'’References http://www.analyticsmarket.com/freetools/ipregex’’
Shorter but will also show 999.999.999.999:<pre>grep -Eo ‘[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}’ </pre>