Jump to content

Resources


effigy
 Share

Recommended Posts

  • 5 years later...

Hello Regex lovers!!!

 

As of March 2012, the old regex resources thread has been locked for five years. Some of the resources are still great, some have disappeared, some are no longer relevant. What's more, many of us current contributors may be aware of new resources that we can share among ourselves. So it seemed like we use a Reload of our Regex Resources section! 

 

To get the ball rolling, as a regex addict, here is the list of regex resources I like at the moment. It's only one person's taste of course.

 

Looking forward to discovering the resources everyone else is digging!!!

:)

 

A. Regex Books

1. For beginner to intermediate regex, my favorite book is The Regex Cookbook, co-authored by Jan Goyvaerts (from RegexBuddy and regular-expressions.info). The book starts out with a strong tutorial. Then the "cookbook approach" provides structure to dive into sub-topics: numbers, urls, markup...

On the "not so strong" side,

- to my eyes, it looks like the code examples are often generated in RegexBuddy---which does not always produce the ideal code.

- to me, many of the "recipes" in the cookbook seem repetitive because they focus on very specific problems (e.g. matching one specific part of an url, then another specific part...), rather than offering solutions or strategies to more "general" problems that you might encounter (e.g how to replace text in certain situations). 

 

2. For advanced regex, my favorite book is Jeffrey Friedl's Mastering Regular Expressions (now in its third edition). True to its title, that book will propel your regex skills a long way toward mastery. 

That being said, it's not a regex bible, and the reader should be aware of some weaker points:

- Some PHP (PCRE) features are not covered (for instance \K)

- Some features could be treated in greater depth (e.g. conditionals, recursion, matching strategy)

- the PCRE engine has evolved since 2007. I benchmarked most of the suggested "optimizations" by clocking a million matches at a time and did not notice real improvement, suggesting that  Philip Hazel & team may have rolled them into the PCRE engine---or that my benchmarking is wrong!  ;)

 

3. I have looked at other books but IMO they don't come close to these two.

 

B. Regex Tuts

 

1. The classic Tut is Jan Goyvaert's regular-expressions.info. Jan is the author of RegexBuddy (below) and the co-author of the Regex Cookbook (above).

 

Strengths:

- a top-notch introduction to regex. The tutorial starts out by giving you a grasp of how a regex engine does its job---very important if you're going to be writing regex.

- covers not just php regex, but also other flavors you might encounter, such as javascript and mySQL. That's really handy.

 

Weaknesses:

It seems to me that Jan tends not to mention the regex features that RegexBuddy does not support... So if you rely on this tut to learn regex, you may be left with a few gaps in your knowledge. For instance, here are some features not yet supported in RB, and that I haven't found on Jan's tut: 

\K --- to reset the reported match

(?R) --- recursive patterns

(?1) --- to repeat sub-patterns

(?| --- to duplicate group numbers

(?(DEFINE)) --- to define sub-patterns

(?(-1)A|B) --- in conditionals, to refer to relative sub-patterns

 

2. Tooting my own Tut, I strongly recommend Andy's Regex Tutorial. AFAIK, along with Jan's site, it's one of the two largest online regex tuts.

 

The focus is a little different:

- lots of examples for those who want their regex to progress to advanced level,

- plugging holes when features are not mentioned or developed in books or other tuts,

- cutting diagonally across topics that are usually presented linearly, for instance:

----> bringing all the bits of (? syntax in one place

----> discussing "good regex style", matching vs capturing strategies, etc.

- grounded in PCRE (PHP), but with examples for regex you might use in other contexts (e.g. Apache, text editors). 

 

Weaknesses:

- at this stage, not ideal for someone who has never tried regex (as a regex addict, I am more interested in advanced regex). Could use a slow introduction, with detailed explanation of how regex engines work.

- you tell me what else could be improved! Comment forms at the bottom of each page, I love feedback.

 

C. Regex Tools

 

1. RegexBuddy

I don't know if I could live without RegexBuddy... well, I guess I could. ;) Here's a permanent link to the latest RegexBuddy demo. I build all my "complex expressions" in RB: in the Test field, I dump my test strings. In the regex field, I type my expression. The matches and captures are highlighted, with instant feedback as you tweak your subject text or expressions. I usually find it faster to craft tricky expressions this way than in PHP.

RegexBuddy has other five-star features:

- support for many other regex flavors (Java, .NET, Javascript etc).

- it will generate "template code" for you if you're not too sure of the syntax to integrate the regex in your language.

- if you're starting out with regex, it will help you build your expression by "inserting tokens"

 

On the "weaknesses side"...

- there's a Grep function to look inside of files, but for those operations I much prefer the next tool, ABA Search and Replace

- the "debug" tab doesn't work for me (clunky interface)

- as reported above, a number of features that I use quite a bit are not supported by RB, so I end up developing these expressions directly in PHP:

\K

(?R)

(?1)

(?|

(?(DEFINE))

(?(-1)A|B)

 

2. ABA Search and Replace

I have fallen in love with this tool, developed by a member of this forum.

ABA Search and Replace is a kind of "grep" tool in the sense that it lets you search for text inside files on your disk... but it's way more powerful than a command-line grep, and, for my taste, far easier to use than Jan's PowerGrep (which I don't own but have demoed).

Once you've specified your files, in one field, you type your regex (and potentially your replacement expression).

In the results box, the matches (and replacements) appear immediately, as you type and modify your expressions! It's magical. You can check boxes to choose which replacements to make, you can copy the matches, etc.

 

On the weaker side, there are a several potential improvements (and Peter assures me that he's working on several of them), such as:

- support for advanced regex syntax

- specifying the names of the files to be searched by using regex

- for me, as a PHP user, it would be 5-star if you could switch to the full PCRE engine in order to tap into the full power of PHP regex. 

 

3. Other tools

There are free desktop and online tools. I don't use them because RegexBuddy is at my fingertips, but I've heard good things about the larsolavtorvik online tester and Rad's regex designer.  Maybe some of you can share what you think of these.

 

 

D. Library of Common Expressions

I rarely look at expression libraries. RegexBuddy's library has a few expressions that could come in handy for frequently asked questions on this board (e.g. matching email IP addresses). Some recommend regexlib.

But frankly, for the largest collection of expressions, it would be hard to beat this board! It's the most active regex board I know of.

 

-------

 

Well, that's my list at the moment... Please contribute your own favorite resources so we can grow our collective knowledge base!

 

Wishing you all a fun day.

:)

 

Peace,

 

ragax

 

 

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.