Product Details
Regular Expression Pocket Reference: Regular Expressions for Perl, Ruby, PHP, Python, C, Java and .NET (Pocket Reference (O'Reilly))

Regular Expression Pocket Reference: Regular Expressions for Perl, Ruby, PHP, Python, C, Java and .NET (Pocket Reference (O'Reilly))
By Tony Stubblebine

List Price: £11.50
Price: £5.98 & eligible for FREE Super Saver Delivery on orders over £5. Details

Availability: Usually dispatched within 24 hours
Dispatched from and sold by Amazon.co.uk

43 new or used available from £4.23

Average customer review:

Product Description

This handy little book offers programmers a complete overview of the syntax and semantics of regular expressions that are at the heart of every text-processing application. Ideal as a quick reference, Regular Expression Pocket Reference covers the regular expression APIs for Perl 5.8, Ruby (including some upcoming 1.9 features), Java, PHP, .NET and C#, Python, vi, JavaScript, and the PCRE regular expression libraries.

This concise and easy-to-use reference puts a very powerful tool for manipulating text and data right at your fingertips. Composed of a mixture of symbols and text, regular expressions can be an outlet for creativity, for brilliant programming, and for the elegant solution. Regular Expression Pocket Reference offers an introduction to regular expressions, pattern matching, metacharacters, modes and constructs, and then provides separate sections for each of the language APIs, with complete regex listings including:

  • Supported metacharacters for each language API
  • Regular expression classes and interfaces for Ruby, Java, .NET, and C#
  • Regular expression operators for Perl 5.8
  • Regular expression module objects and functions for Python
  • Pattern-matching functions for PHP and the vi editor
  • Pattern-matching methods and objects for JavaScript
  • Unicode Support for each of the languages
With plenty of examples and other resources, Regular Expression Pocket Reference summarizes the complex rules for performing this critical text-processing function, and presents this often-confusing topic in a friendly and well-organized format. This guide makes an ideal on-the-job companion.


Product Details

  • Amazon Sales Rank: #17152 in Books
  • Published on: 2007-07-18
  • Original language: English
  • Number of items: 1
  • Binding: Paperback
  • 117 pages

Editorial Reviews

From the Publisher
Ideal as an introduction for beginners and a quick reference for advanced programmers, Regular Expression Pocket Reference is a comprehensive guide to regular expression APIs for C, Perl, PHP, Java, .NET, Python, vi, and the POSIX regular expression libraries. This handy book offers programmers a complete overview of the syntax and semantics of regular expressions, which are at the heart of every text-processing application. When you've reached a sticking point and need to get to a solution quickly, the new Regular Expression Pocket Reference is the book you'll want to have.

About the Author
Tony Stubblebine is an Internet consultant, entrepreneur, and blogger. He's also the author of Regular Expression Pocket Reference, former Engineering Director for Odeo.com and former Engineering Lead for O'Reilly Media. He posts regular updates to his blog, StubbleBlog and regularly releases small websites such as Gem Jack, a repository of documentation for Ruby gems, Rate My Dance Moves, a YouTube mashup, and I Heart Quotes, the Unix fortune program re-imagined for the web.

Excerpted from Regular Expression Pocket Reference by Tony Stubblevine. Copyright © 2003. Reprinted by permission. All rights reserved.
Introduction to Regexes and Pattern Matching

A regular expression is a string containing a combination of normal characters and special metacharacters or metasequences. The normal characters match themselves. Metacharacters and metasequences are characters or sequences of characters that represent ideas such as quantity, locations, or types of characters. The list in the section "Regex Metacharacters, Modes, and Constructs" shows the most common metacharacters and metasequences in the regular expression world. Later sections list the availability of and syntax for supported metacharacters for particular implementations of regular expressions.

Pattern matching consists of finding a section of text that is described (matched) by a regular expression. The underlying code that searches the text is the regular expression engine. You can guess the results of most matches by keeping two rules in mind:

1. The earliest (leftmost) match wins
Regular expressions are applied to the input starting at the first character and proceeding toward the last. As soon as the regular expression engine finds a match, it returns. (See MRE 148-149, 177–179.)

2. Standard quantifiers are greedy
Quantifiers specify how many times something can be repeated. The standard quantifiers attempt to match as many times as possible. They settle for less than the maximum only if this is necessary for the success of the match. The process of giving up characters and trying less-greedy matches is called backtracking. (See MRE 151–153.)

Regular expression engines have subtle differences based on their type. There are two classes of engines: Deterministic Finite Automaton (DFA) and Nondeterministic Finite Automaton (NFA). DFAs are faster but lack many of the features of an NFA, such as capturing, lookaround, and non-greedy quantifiers. In the NFA world there are two types: Traditional and POSIX.

DFA engines
DFAs compare each character of the input string to the regular expression, keeping track of all matches in progress. Since each character is examined at most once, the DFA engine is the fastest. One additional rule to remember with DFAs is that the alternation metasequence is greedy. When more than one option in an alternation (foo|foobar) matches, the longest one is selected. So, rule #1 can be amended to read "the longest leftmost match wins." (See MRE 155–156.)

Traditional NFA engines
Traditional NFA engines compare each element of the regex to the input string, keeping track of positions where it chose between two options in the regex. If an option fails, the engine backtracks to the most recently saved position. For standard quantifiers, the engine chooses the greedy option of matching more text; however, if that option leads to the failure of the match, the engine returns to a saved position and tries a less greedy path. The traditional NFA engine uses ordered alternation, where each option in the alternation is tried sequentially. A longer match may be ignored if an earlier option leads to a successful match. So, rule #1 can be amended to read "the first leftmost match after greedy quantifiers have had their fill." (See MRE 153–154.)

POSIX NFA engines
POSIX NFA Engines work similarly to Traditional NFAs with one exception: a POSIX engine always picks the longest of the leftmost matches. For example, the alternation cat|category would match the full word "category" whenever possible, even if the first alternative ("cat") matched and appeared earlier in the alternation. (See MRE 153–154.)


Customer Reviews

An essential in my work bag4
Okay, let me start by saying this book pretty much repeats information throughout the book and that's simply because it's aim is to show regular expressions in Perl, C, PHP, Python, Java and .NET. So it's a little like getting a manual for your DVD player with instruction in French, English etc. when all you care about is English. However, if you happen to work in various languages (as I have in the past) then this is actually a major selling point.

I do not use regular expression often enough to have instant recall of the metacharacters etc. and so this little book (at a pretty good price) which fits perfectly into a small pocket in my laptop bag is a MUST HAVE for me for those times I do need to write reg. expression code.

I don't leave home without it :-)

Perfect Memory Aid5
A few years ago I read "Mastering Regular Expressions" (the somewhat weightier sibling of this volume) cover to cover and loved every page. It's a great book, readable and filled with detailed explanations but within a few months almost all I had learnt was completely gone.

That is where this pocket reference comes in. The perfect tool to quickly jog your memory and remind you of that unusual rule. If you're new to regular expressions I'd recommend "Mastering Regular Expressions" first but, if you can, buy both. You won't regret it.

Essential pocket guide4
If use perl or a unix style operating system then this little book is a real gem. Unless that this, you can remember what all the funny little characters mean :-) I find myself using perl only a few times a month, so invariably when I want to do something, I know that it is possible, but I have to go searching for my camel to remind myself of the syntax.

Unlike some other pocket guides, this isn't just a reference, but actually contains some tutorial elements.