Regular Expressions

A regular expression (or RE) specifies a set of strings that matches it; the functions in this module let you check if a particular string matches a given regular expression (or if a given regular expression matches a particular string, which comes down to the same thing).

Regular expressions can be concatenated to form new regular expressions; if A and B are both regular expressions, then AB is also a regular expression. In general, if a string p matches A and another string q matches B, the string pq will match AB. This holds unless A or B contain low precedence operations; boundary conditions between A and B; or have numbered group references. Thus, complex expressions can easily be constructed from simpler primitive expressions like the ones described here. For details of the theory and implementation of regular expressions, consult the Friedl book referenced above, or almost any textbook about compiler construction.

A brief explanation of the format of regular expressions follows. For further information and a gentler presentation, consult the Regular Expression HOWTO, accessible from

Regular Expressions :

^ matches the beginning of a string.

$ matches the end of a string.

\b matches a word boundary.

\d matches any numeric digit.

\D matches any non-numeric character.

x? matches an optional x character (in other words, it matches an x zero or one times).

x* matches x zero or more times.

x+ matches x one or more times.

x{n,m} matches an x character at least n times, but not more than m times.

(abc) matches either a or b or c.

(x) in general is a remembered group. You can get the value of what matched by using the
groups() method of the object returned by


Regular Expressions -

Regular Expressions -

"Regular Expression Pocket Reference: Pocket Reference" By Tony Stubblebine, Nathan Torkington Book -

"Mastering Regular Expressions" By Jeffrey Friedl Book -

Regular Expression Engines:

PCRE - Perl Compatible Regular Expressions

The PCRE library is a set of functions that implement regular expression pattern matching using the same syntax and semantics as Perl 5. PCRE has its own native API, as well as a set of wrapper functions that correspond to the POSIX regular expression API. The PCRE library is free, even for building commercial software.

C++ Regular Expression Engines - PCRE, BOOST REGEXJAVA Regular Expression Engines - Apache Regexp


Regular Expression Engines -


BOOST Regex -

Regular Expressions in C++ with Boost.Regex -

Apache Regexp -

Regular Expressions in C++ -