Lists of Characters

The simplest way to use brackets is to list all the acceptable characters within the brackets. In the updated namePattern, the acceptable characters are S and s, so those two characters go inside the brackets. If you wanted to match double or single quotes, you could use ["']. If you wanted to match any lowercase letter in the English alphabet, you could use [abcdefghijklmnopqrstuvwxyz], and if you wanted to match any lowercase or uppercase letter in the English alphabet, you could use [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ]. Wow, that is ugly. There must be a better way.

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.