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
http://www.python.org/doc/howto/.

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 re.search.

Links:

Regular Expressions - http://www.regular-expressions.info/

Regular Expressions - http://www.regular-expressions.info/reference.html

"Regular Expression Pocket Reference: Pocket Reference" By Tony Stubblebine, Nathan Torkington Book -
http://books.google.com/books?hl=en&id=yWiAPqBKuqYC&dq=regular+expressions&printsec=frontcover&source=web&ots=ml6KiIf7MQ&sig=iNm7kbvt_WLeofmkf9mdNyHLlWg&sa=X&oi=book_result&resnum=10&ct=result


"Mastering Regular Expressions" By Jeffrey Friedl Book -
http://books.google.com/books?id=ucwR4KIvExMC&dq=%22Mastering+Regular+Expressions%22+By+Jeffrey+Friedl+Book&pg=PP1&ots=QLuEp_8WLi&sig=o5HmLuhkYgrnRCw6t88-4qe6uu4&hl=en&sa=X&oi=book_result&resnum=4&ct=result

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

Links:

Regular Expression Engines - http://en.wikipedia.org/wiki/Comparison_of_regular_expression_engines

PCRE - http://www.pcre.org/

BOOST Regex - http://www.boost.org/doc/libs/1_35_0/libs/regex/doc/html/index.html

Regular Expressions in C++ with Boost.Regex - http://www.onlamp.com/pub/a/onlamp/2006/04/06/boostregex.html

Apache Regexp - http://projects.apache.org/projects/regexp.html

Regular Expressions in C++ - http://www.ddj.com/184404797