| Pattern | Result | |
|---|---|---|
| . | Matches any character except newline | |
| [a-z0-9] | Matches any single character of set | |
| [^a-z0-9] | Matches any single character not in set | |
| \d | Matches a digit, same as [0-9] | |
| \D | Matches a non-digit, same as [^0-9] | |
| \w | Matches an alphanumeric (word) character [a-zA-Z0-9_] | |
| \W | Matches a non-word character [^a-zA-Z0-9_] | |
| \s | Matches a whitespace character (space, tab, newline...) | |
| \S | Matches a non-whitespace character | |
|   |   | |
| \n | Matches a newline | |
| \r | Matches a return | |
| \t | Matches a tab | |
| \f | Matches a formfeed | |
| \b | Matches a backspace (inside [] only) | |
| \0 | Matches a null character | |
| \000 | Also matches a null character because ... | |
| \nnn | Matches an ASCII character of that octal value | |
| \xnn | Matches an ASCII character of that hexadicimal value | |
| \cX | Matches an ASCII control character | |
| \metachar | Matches the character itself (\|,\.,\*...) | |
|   |   | |
| (abc) | Rembers the match for later backreferences | |
| \1 | Matches whatever the first set of parens matched | |
| \2 | Matches whatever the second set of parens matched | |
| \3 | and so on... | |
|   |   | |
| x? | Matches 0 or 1 x's, where x is any of the above | |
| x* | Matches 0 or more x's | |
| x+ | Matches 1 or more x's | |
| x{m,n} | Matches at least m x's but nore more than n | |
|   |   | |
| abc | Matches all of a, b, and c in order | |
| fee|fie|foe | Matches one of fee, fie, or foe | |
|   |   | |
| \b | Matches a word boundry (outside [ ] only) | |
| \B | Matches a non-word boundry | |
| ^ | Anchors match to the beginning of a line or string | |
| $ | Anchors match to the end of a line or string | |
|
Pattern Binding Operator
The pattern binding operator (=~) is described in perlop.pod:
The binding operator works on that part of the scalar that matches the pattern in the match, substitution or translation, changing it "in place." Example: $data =~ s/"//g; This statement searches the scalar $data for all double-quotes (via 'g' switch) and removes them (i.e., replacing with nothing.) The value in $data then has no double-quotes. When the description speaks of a 'return value' as successful or not, it can be used in conditional tests. For example: if ($data =~ s/"//g){print "Success\n";}
or
$success = $data =~ s/"//g;
The first would print "Success" if pattern found and substitution made. The variable $success would contain a true value if the double-quote character is found. When used with substitution, it would contain the number of substitutions made. (Other right side operations return other values, if successful.) | ||
