Meta Character or Pattern | Description |
\ | Marks
the next character as special. For example the Regexp pattern /n/ matches the character "n". If you need to check for \n (The new-line character) you must mark the n as special by using a back-slash character. /\n/ matches a linefeed or newline character. |
^xxx | Checks
if the string xxx is at the beginning of the subject string.
e.g : $str=~ /^UNIX/ returns true if "UNIX" is at the beginnig of the string contained in $str. |
zzz$ | Checks
if the string zzz is at the end of the subject string.
e.g : $str=~ /UNIX$/ returns true if "UNIX" is the last 4 characters of the string contained in $str. |
A* | Matches if the string "A" is repeated 0 or more times. Please note that the regexp "/A*/" WILL MATCH ANY string. /zo+/ matches "zoo" and "zoa." |
A+ | Matches if the string "A" is repeated 1 or more times. /zo+/ matches "zoo" but not "zoa." |
A? | Matches if the string "A" is repeated 0 or 1 time. /zo?/ matches /zoa/ but not /zoo/. |
A{n} | Matches if the string "A" is repeated exactly n times. |
A{n,} | Matches if the string "A" is repeated at least n times. |
A{n,m} | Matches if the string "A" is repeated at least n and at most m times. |
A{,m} | Matches if the string "A" is repeated at most m times. |
. | Matches any single character except a newline character. |
[xyz] | Matches any one of the enclosed
characters exists in the subject string. You can use range of values as the list of patterns. e.g. [0-9] represents [0123456789] an can be used to test if a character is a digit. Another popular range to test against is [a-zA-Z] which matches all letters; both uppercase and lowercase. |
[^xyz] | Is the negated version of the above test. It reads "If character is NOT one of x, y and z". |
A\b | Matches if "A" is at a word boundary. e.g /\bUgur\b/ matches " Ugur " but not to " Ugurlu". |
\B | NOT word-boundary |
\d | Matches a digit. |
\D | Matches a nondigit. |
\n | Matches a linefeed (new line) character. |
\r | Matches a carriage return character. |
\s | Matches any white space including spaces, tabs, form-feeds, line-feeds |
\S | Matches any nonwhite space character. |
\t | Matches a tab character. |
\w | Matches any word character (characters allowed in English words). Includes the underscore. Equivalent to [A-Za-z0-9_]. |
\W | Matches any nonword character; like punctuation characters |