Shortcuts for Brackets

Most commonly, the backslash turns letters into groups. For instance, \s matches any type of whitespace character, such as a space, a tab, and a newline (among others). The backslash can also represent a character that cannot be used literally in a regular expression. For instance, a regular expression generally has to be all on one line, so to represent a new line, you need to use \n because you can’t just press Enter. The following table describes all the characters that take on special meaning with the backslash.

Image

With this knowledge, we can make our phone number pattern a little more readable. Our pattern currently repeats ...

Get Learning to Program now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.