Expressions

^ = Beginning of a line; also represents the characters not in the range of a list
$ = End of a line
[ab] = a or b
[1-5] = 1, 2, 3, 4 or 5
[:alpha:] or [A-Za-z] = Alphabetic characters
[:alnum:] or \w = Alphanumeric characters
[:blank:] = Blank characters: space and tab
[:digit:] or \d = Digits: ‘0 1 2 3 4 5 6 7 8 9’
[:lower:] = Lower-case letters: ‘a b c d e f g h i j k l m n o p q r s t u v w x y z’
[:space:] or \s = Space characters: tab, newline, vertical tab, form feed, return, and space
[:upper:] = Upper-case letters: ‘A B C D E F G H I J K L M N O P Q R S T U V W X Y Z’
[:punct:] = Punctuation symbols . , ” ‘ ? ! ; : # $ % & ( ) * + – / < > = @ [ ] \ ^ _ { } | ~
. = Wildcard (Joker)
? = The preceding item is optional and will be matched, at most, once
* = The preceding item will be matched zero or more times
+ = The preceding item will be matched one or more times
{N} = The preceding item is matched exactly N times
{N,} = The preceding item is matched N or more times
{N,M} = The preceding item is matched at least N times, but not more than M times
\b = Matches the empty string at the edge of a word
\B = Matches the empty string provided it’s not at the edge of a word
\< = Match the empty string at the beginning of word
\> = Match the empty string at the end of word

Ex :
[^0-9] or [^[:digit:]] or \D = Matches any character which is not a digit
[^[:alnum:]] or \W = Match any character NOT the range 0 - 9, A - Z and a - z
^$ = Empty line
^..$ = A line with 2 characters
^\.[0-9] = A line starting with a dot and a digit
[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3} = Ip address

Leave a Reply