The predefined classes in the prior tutorial are not the only situations where an ordinary letter can be escaped in order to give it a special meaning. There are a number of common characters that cannot be easily typed in from the keyboard where a special escape combination is provided in order to allow that character to be included in the regular expression.
One of the predefined classes was \s which represents any whitespace character. Many of these whitespace characters have their own individual escape codes since they cannot be directly typed into the field as they would break the Javascript formatting if they were.
- \t tab
- \n new line
- \r carriage return
- \f form feed
- \v vertical tab
- \0 null character
In addition to these whitespace characters there are also special escape characters that allow you to specify other control characters in your regular expressions.
- \a alert
- \e escape
- \cX Control character obtained by pressing the CTRL key and the X key (where X is any alphabetic key) together
By using these special predefined escape characters, in addition to the ones we have already looked at, you can specify most of the individual character values that you would ever want or need to use in a regular expression.