...

/

Formatting the Output of Regular Expressions

Formatting the Output of Regular Expressions

Learn about the components of regular expressions and the art of desired outputs from regular expressions.

We'll cover the following...

Components of a regular expression

Below are the basic components that make up a regular expression:

Characters : These appear in the string being matched. For example, the characters a and b appear in the string abc.

Metacharacters : These have a special meaning in a regular expression. For example, the metacharacter . (dot) matches any character.

Quantifiers : These specify how many of the previous characters, or groups of characters, must be present. For example, the quantifier * (asterisk) means “zero or more occurrences.”

Regular Expression Options : These change the way a regular expression is matched. For example, the i (ignore case) or RegexOptions.IgnoreCase option means that the case should be ignored when matching.

The components of a regular expression

In the next section, we take a closer look at each of these components.

Characters

Characters are the most basic components of a regular expression. They match themselves in the string being matched.

For example, the character a matches the string a", aa, and aaa. However, it does not match b or cb.

Metacharacters

Metacharacters have a special meaning in a regular expression. They don’t match themselves. Instead, they match other characters or groups of characters.

For example, the metacharacter . (dot) ...