Character Class Matching
Character class matching is useful when the subject text contains one of a subset of characters combined with a known text string. Subsets are defined enclosing the characters in square brackets, e.g. [CMS]. A shorthand notation is provided for commonly used character sets.
| Symbol | Meaning | Example |
| [...] | Match any one of the characters in the set - defined in square brackets | [CMS]at matches "Cat", "Mat" and "Sat" but not "Rat" |
| [^...] | Exclude matches containing characters in the set | [^CMS]at matches "Rat" but not Cat, Mat or Sat |
| [..-..] | The - character is used to define a character class range - very useful for validating IP addresses, telephone numbers, social security numbers etc. | [0-2][0-9][0-9] matches "255" but not 512 |
| . | Match any character except a line terminator such as the newline character | .oodle would match "doodle", "noodle" and "poodle" |
| \w | Match any alphanumeric character including the underscore. | \Windows\w\w would match "Windows95" and "WindowsXP" but not "Windows Vista" |
| \W | Match any character that is not alphanumeric or the underscore - equivalent to [^a-zA-Z0-9_] | CSS\W\w matches "CSS 3" but not CSS_3 |
| \d | Match any digit - equivalent to [0-9] | Windows \d\d matches "Windows 95" but Windows XP |
| \D | Match any non digit character - equivalent to [^0-9] | Windows \D\D matches "Windows XP" but Windows 95 |
| \s | Match any space character - equivalent to [\n\f\r\t\v]. | Windows\s\w\w matches "Windows 95" but not Windows-95 or Windows_XP |
| \S | Match any non-space character - i.e. [^\n\f\r\t\v]. | Windows\S\w\w matches "Windows_95" but not Windows 95 or Windows XP |
Regular Expression Sandbox
Model
Data
Do not wrap the model expression in a /.../ pair. The characters
Do not wrap the model expression in a /.../ pair. The characters
^$.?*!+:=()[]{}|\\ must be escaped - except when then occur inside a character class. Invalid characters will be grayed out.| Result | Left Text | Match | Right Text |
|---|---|---|---|
Download