AB's Useful Box - Regular Expressions

When writing Linux/Unix shell scripts, the most powerful commands utilise Regular Expressions.

 

Following is a list of the more common:

Wildcard Characters

. = any single characters
[abc] = any single character in the set
[a-c] = any single character in the range
[^abc] = any single character not in the set
[^a-c] = any single character not in the range


Modifiers

* = zero or more of the previous char
\+ = one or more of the previous char
\? = zero or one of the previous char
\{i\} = exactly i of the previous character
\{i,\} = i or more of the previous char
\{i,j\} = i to j of the previous character


Anchors

^ = line begins with
$ = line ends with
\< = word begins with
\> = word ends with


regex Combinations

.* = zero or more of any character
[a-Z]* = zero or more letters
\<cat\> = the word 'cat'
ab..ef = ab and ef separated by two chars
.\{32\} = 32 of any character
\* = a literal asterisk

 

 

Updated: 05-Jul-2009
index