| LITERALS |
All characters are literals except metacharacters:
. | * ? + ( ) { } [ ] ^ $ \
These characters are literals when preceded by a "\".
Inside sets "[]" only "^","\" and "-" should be preceded by a "\".
A literal is a character that matches itself.
|
| |
| METACHARACTERS |
| . | Wildcard - matches any single character (except newline) |
| [ ] | Sets - matches a single character that is contained within the brackets |
| | | The choice (or set union) operator: match either the expression before or the expression after the operator |
| [^ ] | Matches a single character that is not contained within the brackets |
| ^ | Matches the start of the line |
| $ | Matches the end of the line |
| ( ) | Parenthesis -treat the expression enclosed within the brackets as a single block |
| {x,y} | Match the last "block" at least x and not more than y times (may be {x,} but not {,y}) |
| * | Match the last "block" zero or more times (the same as the {0,}) |
| + | Match the last "block" one or more times (the same as the {1,}) |
| ? | Match the last "block" zero or one time (the same as the {0,1}) |
| |
| CHARACTER CLASSES |
| [[:alnum:]] | Any alpha numeric character. |
| [[:alpha:]] | Any alphabetical character a-z and A-Z. |
| [[:digit:]] | Any digit 0-9. |
| [[:xdigit:]] | Any hexadecimal digit character, 0-9, a-f and A-F. |
| [[:space:]] | Any whitespace character. |
| [[:blank:]] | Any blank character, either a space or a tab. |
| [[:lower:]] | Any lower case character a-z. |
| [[:upper:]] | Any upper case character A-Z. |
| [[:print:]] | Any printable character. |
| [[:graph:]] | Any graphical character (any printable character except space or a tab). |
| [[:punct:]] | Any punctuation character - .,:;|\/?!~'"`<>{}[]!@#$%^&*_-+=. |
| [[:cntrl:]] | Any control character. |
| |
| EXAMPLES |
| Pattern | Match |
| abc | "abc" only |
| [abc] | "a" or "b" or "c" only |
| [a-z] | any lowercase character |
| [^a-z] | any character that isn't a lowercase |
| [1-3] | "1" or "2" or "3" |
| ab*" | "a" or "ab" or "abb" etc |
| ab+ | "ab" or "abbb" etc but not "a" |
| ab? | "a" or "ab" only |
| ab{2,4} | "abb" or "abbb" or "abbbb" only |
| ab{2} | "abb" only |
| ab{2,} | "abb" or "abbbb" etc |
| ab|cd | "ab" or "cd" only |
| [ab]+cd | "acd" or "bcd" or "aacd" or "bbcd" or "ababcd" etc |
| ([aA]c | [bB]c) | "ac" or "Ac" or "bc" or "Bc" only |
| ^abc | any string that starts with "abc" |
| ^abc$ | a string that starts and ends with "abc" |
| ^[a-zA-Z] | any string that starts with a letter |
| ^.{3}$ | any string with exactly 3 characters |
| \\ | backslash "\" |