Search Patterns |
* |
Matchs a pattern zero or more times |
? |
Matches pattern once or none at all. |
+ |
quantifier to match a pattern one or more times. |
. |
A single dot, '.', matches any character except newline, '\n' |
\t |
Tab character |
\w |
Word character, or [a-zA-Z0-9_]. \W negates |
\d |
Digits. Shortcut for [0-9]. \D negates |
\b |
word boundry. Matches whole words. e.g., /\bpattern\b/ will match single word "pattern" but not "patternA" or "APattern" |
[0-9] |
Finds 0 1 2 3 4 5 6 7 8 9 |
[a-z] |
Finds a b c d ... x y z. Also, [A-Z] finds A B C ... X Y Z |
[abc$%!] |
Matches single characters: a, b, c, $, %, and ! |
[^abc] |
The ^ negates. Perl will not match these characters. e.g., [^\d] will not match digits. |
\s |
Matches whitespace. Same as [\f\t\n\r ], form-feed, tab, newline, carriage return, and space character. \S negates. |
() |
Parenthese are used to group patterns. Useful for quantifiers. e.g., /(pattern)+/. Used with memory parenthese are backreferences, \1, \2... So, /(["'])hello\1/ will match either quotes, hello, and which ever quote first found, that is, it will match "hello" and 'hello'. See also $1 which works after the search pattern. |
{} |
General Quantifier matches pattern between n min and n max times. e.g., /x{3,9}/ this will match x anywhere from 3 times to 9 times. /x{5}/ matches x five times only. |
| |
The pipe character is logic "or". e.g., /(thisOne)|(thatOne)/, will math "thisOne" or it will match "thatOne". |
$`$&$' |
$& is the matched pattern. $` is what's before the match and $' is what's after the match |
^$ |
^ means string must start with this pattern. $ means string must end with this pattern. Kind of like left and right functions in some programming languages. |