Regex 101-03: Character Classes

Character Class Basics

Character classes try to match an individual character within square brackets: [abc] matches and a, b or c

Character classes are case sensitive: [ABC] matches A, B or C

Character classes can do ranges of characters [A-Za-z0-9]

Also, you can negate a character class as well (matches everything not specified) [^AEIOUY]

Note: To match aadd it to the end of the capture group [A-Z-]

You can also do it by placing a backslash in front of the character. [\-A-Z]. This is called ‘escaping’. Later you will see some characters have special meaning that can be escaped to it’s literal meaning and some other characters are given meaning by the backslash. It’s all wacky regex fun!

πŸ‘ Get Blog Updates

πŸ“ Latest Posts

0Shares
0

Leave a Reply