The most basic type of character class is a set of characters placed side-by-side within square brackets "[]". For example, the regular expression [bcr]at, matches the words "bat", "cat", or "rat" because it uses a character class (that includes "b","c", or "r") as its first character. Character classes only match singular characters unless a quantifier is placed after the closing bracket. For examples using quantifiers with character classes, see Compound Character Classes. The following table shows how to use simple character classes in regex searches.
Example 1: Use a character class to match all cases of the letter "s".
Java[Ss]cript
JavaScript Javascript
javascript javaScript
Example 2: Use a character class to limit the scope of alternative matches on the words gray and grey.
gr[ae]y
gray grey
gry graey
Example 3: Use a character class to match any one digit in the list.
[0123456789]
5 0 9
x ? F
Example 4: To simplify the previous example, use a hyphen "-" within a character class to denote a range for matching any one digit in the list.
[0-9]
5 0 9
234 42
Example 5: Use a hyphen "-" within a character class to denote an alphabetic range for matching various words ending in "mail".
[A-Z]mail
Email Xmail Zmail
email mail
Example 6: Match any three or more digits listed in the character class.
[0-9]{3,}
012 1234 555 98754378623
10 7