Introduction to a Regular Expression

A regular expression is a pattern that abstractly describes the desired format of a string. In this way, regular expressions are more powerful than a substring, and can describe many different elements that resemble character data. You might use a regular expression to filter data from a file, or validate user inputs to a program.

The basic elements of a regular expression are its tokens and quantifiers. A token describes what character, or type of character, should appear in the string. A quantifier describes how many of that token there should be. Quantifiers can be exact numbers or ranges of numbers.

By default, a string matches a regular expression if the match occurs anywhere in the string. However, you can confine the match to the beginning, end, or entirety of the string, if desired.

The maximum length of a regular expression, including its delimiters and options, is 255 characters.

The following tables appear at the end of this section, and describe different types of characters:
  • Table 1: Invalid delimiters
  • Table 2: Word characters
  • Table 3: Whitespace characters
  • Table 4: Reserved characters