Softpanorama
(slightly skeptical) Open Source Software Educational Society

May the source be with you, but remember the KISS principle ;-)

Google   


Mastering Regular Expressions

***+ Mastering Regular Expressions : Powerful Techniques for Perl and Other Tools (Nutshell Handbook)
Jeffrey Friedl / Paperback / Published 1997
 
The book is not limited to Perl. Perl just over-rely on them in parsing the text. Regexs are also used in such  languages as Python, TCL, Expect, AWK, Lex, in utilities like Grep Egrep, and most editors including Emacs, vi, and sed. See also WEB site Mastering Regular Expressions   that contains links to the additional material from the book.
 
Regular expressions are a mixed blessing. Like other functional languages using regular expressions is not that difficult after you have (a lot of) experience, but at the beginning learning is usually very frustrating. People just do not understand that regex evolved in a very complex language. To make things worse you just cannot accomplish simple things without learning a lot of stuff. Semantic of some characters in regular expressions is different from Perl and is dependent upon context (for example the meaning of  "^" in  /^a/ and /[^a]/ ).
 
To make things worse documentation about regular expressions is usually bad and uncompleted. There is no regular expression debugger. So the best way to go is to create a list of typical regular expressions that you may need and debug them beforehand (cookbook approach). Generally the best way out is to avoid complex regular expressions (KISS principle) and use non-greedy matching whenever possible. And here the book can help a lot  as it contains many useful examples, although there should be more. Among them:


[0-9]+(\.[0-9])+  -- regular expression for matching IP addresses

<H[1-6]> * \\H[1-6]     -- HTML headers

^(From|Subject|Date): --  line in the e-mail message header (it is important to understand that the alteration is not greedy

See also review in DDJ

Copyright © 1996-2008 by Dr. Nikolai Bezroukov. www.softpanorama.org was created as a service to the UN Sustainable Development Networking Programme (SDNP) in the author free time. Submit comments This document is an industrial compilation designed and created exclusively for educational use and is placed under the copyright of the Open Content License(OPL). Original materials copyright belong to respective owners. Quotes are made for educational purposes only in compliance with the fair use doctrine.

Standard disclaimer: The statements, views and opinions presented on this web page are those of the author and are not endorsed by, nor do they necessarily reflect, the opinions of the author present and former employers, SDNP or any other organization the author may be associated with. We do not warrant the correctness of the information provided or its fitness for any purpose.

Last modified: November 08, 2008