Home Linux Utils

^     beginning of line
$     end of line
\b    word boundary
\B    a non word boundary

Single Characters:

.     any one character
\d    any digit from 0 to 9
\w    any word character (a-z,A-Z,0-9)
\W    any non-word character
\s    any whitespace character (tab, new line, form feed, end of line, carriage return)
\S    any non whitespace character

Quantifiers (refer to the character that precedes it):

?     appearing once or not at all
*     appearing zero or more times
+     appearing one or more times
{min,max} appearing within the specified range

contains 4 letters


line starts with a number


line does not start with a number


Not a vowel


Defines a marked subexpression. The string matched within the parentheses can be recalled later 

\( \)

ifconfig  | sed -n 's/.*dr:\(.*\) Bc.*/\1/p'

Match any character except : return or newline


example with sed to change the encrypted password in /etc/shadow

perl -pi -w -e 's/^myuser:[[^:\r\n]]*:/myuser:encryptedPassword:/' /etc/shadow