Using regular expressions
Regular expressions are patterns of text that can be used by a regular expression parser to search a string for text that matches the pattern, and if required, replace the matched items with other text.
Defining regular expressions
A regular expression (regex) is made up of characters that define a pattern. The expression contains special symbols that are meaningful to the parser, and if you want to use those symbols in the search pattern in the expression then you can escape them with a backslash (\
). Your code will typically pass the expression as a string
object to an instance of the regex
class as a constructor parameter. This object is then passed to functions in <regex>
that will use the expression to parse text for sequences that match the pattern.
The following table summarizes some of the patterns that you can match with the regex
class.
Pattern | Explanation | Example |
literals | Matches the exact characters |
|
[group] | Matches a single character... |