grep.extracts logo grep.extracts
resources on regular expressions

What's this?

This site attempts to collect some useful resources on regular expressions. A good compilation of regex links is also given by Jorn Barger. Another regex info site with a similar focus has been compiled by Jan Goyvaerts.
Roughly, the term Regular Expressions, or shortly regex, describes a widely distributed computer syntax that offers meta-characters to perform powerful text search and replace actions.
 

Online Resources

Languages
 

Perl

See the relevant perl documentation, for v5.6.1: regex language and regex operators, regex tutorial and also the split function. For further perl related resources on regular expressions see the perl.com regex resources site.

PHP

PHP supports regular expressions using a POSIX-extended syntax as well as Perl-compatible syntax. Again, see also the split function.

Python

With the re module, Python offers Perl-style regular expression operations. Earlier versions of Python provided an Emacs-style regexp implementation using the regex module (which is obsolete as of Python 1.5 but is still supported due to legacy code).

MySQL

MySQL uses Henry Spencer's (extended) implementation of regular expressions; mysql.com offers a short reference page as well as help with pattern matching based on extended regular expressions. A tabular listing of commonly used elements of MySQL regular expressions is given here.

AppleScript

On the Macintosh, following scripting additions ("osaxen") enable you to use regular expressions within Apple's AppleScript language: Leonard Rosenthol developed the excellent RegEx Commands scripting addition; see the GrepRename script page for an example how to implement this osax and for a list of most of its supported meta-characters. Late Night Software also had a Regular Expressions scripting addition that was part of the now discontinued LNS Scripting Additions (commercial) and the publicly available Script Tools collection. Other regex supporting scripting additions are the FB package and mgrep (which is also available as standalone app).

Others...

For other languages (e.g. C/C++/VC++, Delphi, Java, JavaScript, Python) see Jeffrey Friedl's regex-related links.

Tutorials
 

General

A good starting point may be Google's Web Directory listing of tutorials on regular expressions. A nice basic introduction to regular expressions is given by Stephen Ramsay. Tony Stubblebine, author of the Regular Expression Pocket Reference (see below), shares some good tips in an ONLamp.com article named "Five Habits for Successful Regular Expressions".

Perl

Just type something like "regular expression tutorial perl" into google to get a first impression about the tremendeous amount of regexp tutorials available for perl. Again, you may also take a look at the Google Web Directory entry on Regular Expressions in Perl. The following tutorial was quite useful to me: Perl.com features an article by Simon Cozens ("Regexp Power") about "some of the less well-known or less understood parts of the regular expression language". Finally, you can test your search patterns online at the Java-based Perl Regular Expression Simulator.

Python

A.M. Kuchling has compiled a Regular Expression HOWTO, an "introductory tutorial to using regular expressions in Python with the re module. It provides a gentler introduction than the corresponding section in the Library Reference" (see above).

BBEdit

Cari D. Burstein has written an excellent BBEdit Grep Tutorial on how to use BBEdit's grep implementation. Based on this tutorial I have compiled a reference page in german language (Grep-Sonderzeichen für BBEdit) that lists and explains BBEdit's Grep expressions (but unfortunately still lacks discription of the new PCRE syntax).

 

Book Resources

General
 

Regular Expression Pocket Reference

This O'Reilly Pocket Reference gives an overview of the syntax and semantics of regular expressions. It claims to offer a "comprehensive guide to regular expression APIs for C, Perl, PHP, Java, .NET, Python, vi, and the POSIX regular expression libraries".

Mastering Regular Expressions

If you're serious about regular expressions, this is your only choice: Jeffrey Friedl's book offers an excellent in depth description of the topic. It serves both, as an introduction to the beginner as well as an advanced course for the experienced reader, explaining how regex works under the hood and how to actually use it in different environments. Some chapters are available online: 1st edition: chapter 4 (Powerful Techniques for Perl and Other Tools), 2nd edition: chapter 8 (Java) and chapter 9 (.NET) in PDF format. Further information about this book is provided by the publisher (1st edition, 2nd edition) and by the author himself (1st edition, 2nd edition) who also describes what has changed between the first and second edition of the book in an O'Reilly Network article.

Perl
 

Lerning Perl

This Book by Randal L. Schwartz and Tom Christiansen has an introductionary chapter on perl's regular expressions. Though focused on perl's regex implementation, it may serve as a good introduction to the concept of regular expressions as well.

Effective Perl Programming

Joseph N. Hall's book features also a chapter on regular expressions, which is available online in PDF format.

 

Regex Capable Applications

Mac
 

BBEdit

Powerful text & html editor that uses the perl compatible regular expressions (PCRE) package. The PDF documentation which comes with the app package (choose "BBEdit User Manual" from BBEdit's Help menu) features a complete chapter about "Searching with Grep". It provides a nice overview of BBEdit's regex implementation and may serve as an excellent introduction to the concept of grep itself. If you don't own BBEdit (yet ;-), get the BBEdit Demo package which will also include the full PDF documentation. A list of BBEdit grep tutorials is given above.

TextWrangler

TextWrangler is Barebones budget-priced alternative text editor to its flagship product BBEdit. It offers almost all of the search & replace functionality that's available in BBEdit, including support for perl compatible regular expressions (PCRE). The Barebones website lists feature comparisons between TextWrangler & BBEdit as well as between TextWrangler & BBEdit Lite (discontinued).

Pepper

Innovative text & html editor that also uses the perl compatible regular expressions (PCRE) package.

Alpha

Intensely customizable Emacs-like text & html editor with perl-style regular expressions.

Jedit

Text editor that supports regular expressions (compatible with 2-byte characters) for search functions.

Emacs

Emacs port to the MacOS.

Nisus Writer

Word processor that features grep and supports English-like phrases instead of traditional Unix-style expressions. A similar approach was offered by PreFab Software's (discontinued) TextMachine, a scriptable app w/o an interface, that got an in depth review by TidBITS-author Matt Neuburg.

Nisus Writer Express

Very promising writing and editing tool for Mac OS X that offers a powerful, three-level Find and Replace function: "Normal Find" mode is offered for simple finds, while the "PowerFind" mode offers to write search patterns in English-like phrases, finally in "PowerFind Pro" mode you can type real regular expressions. Even cooler, the application offers a convenient expression browser as well as automatic expression conversion from English-like phrases to traditional Unix-style expressions.

Microsoft Word

Even Microsoft Word offers support for regular expressions (you need to enable the "Use wildcards" check box), the expression syntax is non-standard, though.

Mailsmith

Robust email client that supports much of BBEdit's core functionality, e.g. the perl compatible regular expressions (PCRE) package.

MgrepApp

Multibyte-aware file search utility that let's you scan whole directories with grep. Features a convenient "Regex" menu that let's you compose grep expressions by choosing from English-like phrases.

SpeedSearch

File search utility that utilizes the perl compatible regular expressions (PCRE) package. Offers a rich feature set, e.g. "goto line" support for CodeWarrior, BBEdit and Alpha.

KeyQuencer

This macro utility from Binary Software offers a regex capable match command.

MacPerl

MacPerl is a port of the perl scripting language to the classic MacOS, providing perl's powerful regular expression syntax for any text or data manipulation.

Others...

Other Macintosh software supporting regular expressions: REALbasic, Analog for Mac, PageSucker, MacVim

Win
 

HomeSite

Feature-rich text & html editor for Win 98/NT/2K/ME/XP.

Pepper

Pepper (see above) is not only available for the Mac but also for Win 2K/XP.

Emacs

Emacs port for DOS by Morten Welinder.

PowerGREP

Grep search & replace tool (Win 9x/NT/2K/ME/XP) with support for perl-style regular expressions. Among other things, it lets you preview the replacements, offers an undo function and has a "sequence" feature that lets you execute multiple search and replace operations in one step.

EditPad Pro

Win 9x/NT/2K/ME/XP text editor that also supports perl-style regular expressions.

Finders Keepers

Win 9x/NT/2K/XP file search utility.

Advanced Find & Replace

Another Win 9x/NT/2K/ME/XP file search utility with perl-style regular expressions.

XReplace-32

Win 9x/NT/2K/XP search & replace utility with support for simple regular expressions.

Search and Replace for Windows

Search and replace utility with egrep-like syntax that's supported by a separate Regular Expression Wizard application which aims to help in creation, understanding, and debugging of regex patterns used by the Search and Replace utility.

Others...

NoteTab

Unix
 

grep

The documentation for GNU grep is available online.

ngrep

Grep features applyied to the network layer.

Emacs

The ultimate text editor on *nix platforms.

VIM (Vi IMproved)

The VIM online documentation has some chapters explaining the use of regular expressions (chapters 03.9 and 27). The VIM book is also available online, both, in HTML and converted to PDF.

sed

The stream editor sed supports basic regular expressions with two additions explained in the sed man pages. For further info about sed checkout the sed pages compiled by Sven Guckes and Eric Pement.

Others...

mboxgrep, GNU regex library (documentation for regex 0.12), ls, egrep, fgrep, nedit

 


Contact: Matthias Steffens  |  Last Updated: 23-Aug-03