What kind of special characters (escape sequences) can I use in Perl regular expressions?

By Alvin J. Alexander, devdaily.com

You can do many crazy things with Perl regular expressions, but many times you just need to use an escape character (or escape sequence) in a regular expression. I'm often asked what escape sequences you can use in Perl regular expressions, so without any further ado, here is a simple list of "special" characters (such as the [Tab] character) can be matched by the Perl regular expressions:

Character Sequence What it Matches
\a Alarm
\d A digit, the same as [0-9]
\D A non-digit
\e Escape
\f Form feed
\n Newline character
\r Carriage return
\s A whitespace character, the same as [ \t\n\r\f]
\S A non-whitespace character
\t Tab
\w A word character, the same as [a-zA-Z_0-9]
\W A nonword character

devdaily logo