Character Codes
Plain characters like 'a', 'X', '9' – just match exactly. (a period) – matches any single character except "\n"
\w -- matches a "word" character: a letter or digit [a-zA-Z0-9]
\W -- (upper-case W) any non word character
\s -- matches a single whitespace character – space, newline, return, tab, form [ \n\r\t\f]
\S -- (upper-case S) any non whitespace character
\t, \n, \d -- tab, newline, decimal digit [0-9]
\ -- inhibit the "specialness" of a character. So, for example, use \. to match a period or \\
to match a slash
/ Variants
"i" after the last / makes it case-insensitive
"m" before the first slash lets you use a delimiter such as "
Examples
"piiig" =~ /p...g/ ==> TRUE . = any char
"piiig" =~ /ii/ ==> TRUE you do not need to use up the whole string
"piiig" =~ /p....g/ ==> FALSE the whole pattern must match
"piiig" =~ /p\w\w\wg/ ==> TRUE \w = any letter or digit
"p123g" =~ /p\d\d\dg/ ==> TRUE \d = 0..9 digit
"piiig" =~ /pIiIG/i ==> TRUE, "i" at end makes it case insensitive
"piiig" =~ m"piiig" ==> TRUE "m" allows a delimiter other than /
No comments:
Post a Comment