Regular Expression - Backslash Generic Character Class (shorthand)

About

The use of backslash are called shorthand) and specifies:

Syntax

The syntax of a shorthand in a regular pattern.

\[a-zA-Z]??

where:

  • the first character is a backslash
  • the second is a letter

Most well known

Generic character types Description Equivalent to
\d any decimal digit [0-9]
\D any character that is not a decimal digit [^0-9]
\h any horizontal whitespace character
\H any character that is not a horizontal whitespace character
\s any whitespace character [\f\n\r\t\v​\u00a0\u1680​\u180e\u2000​-\u200a​\u2028\u2029\u202f\u205f​\u3000\ufeff]
\S any character that is not a whitespace character [^ \f\n\r\t\v​\u00a0\u1680​\u180e\u2000​-\u200a​\u2028\u2029\u202f\u205f​\u3000\ufeff]
\v any vertical whitespace character
\V any character that is not a vertical whitespace character
\w any “word” character [A-Za-z0-9_]
\W any “non-word” character [^A-Za-z0-9_]

These character type sequences can appear both inside and outside character classes. They each match one character of the appropriate type. If the current matching point is at the end of the subject string, all of them fail, since there is no character to match.


Powered by ComboStrap