Other Resources:
Using character class [...]
What is a character class? How to specify a character class in a regular expression?
How to write a regular expression using character classes to capture 7 digits phone numbers from this example string "123-4567, 123 4567 or 1234567"?
✍: FYIcenter.com
![]()
A character class allows a set of possible characters, rather than just a single character, to match at a particular point in a regex. Character classes are denoted by brackets [...] , with the set of characters to be possibly matched inside.
Here are some examples of character classes:
[bcr]at # matches 'bat', 'cat', or 'rat' [yY][eE][sS] # match 'yes' in a case-insensitive way
The regular expression using character classes to capture 7-digit phone numbers from a text file:
[0123456789]{3}[- ]?[0123456789]{4}
[0123456789] - character class of any decimal digits
{3} - repeating 3 times
[- ]? - '-', ' ' or no character
2013-02-02, 0👍, 0💬
Popular Posts:
All credit card numbers issued by American Express must start with 34 or 37 and have 15 digits. For ...
How to capture the Soso Spider entries from Web log file? Here are some Web log file entries: 127.0....
All credit card numbers issued by JCB have 3 sets of numbers: JCB cards start with 2131 have 15 digi...
All credit card numbers issued by American Express must start with 34 or 37 and have 15 digits. For ...
According to the IEEE 802 specification, a MAC address has 6 groups of 2 hexadecimal digits separate...