The Regular Expressions Coach

Although there is no doubt that regular expressions are incredibly useful, they also easily get out of hand when trying to match complex strings. Furthermore, anything past twelve or so characters gets hard to read and understand, which is a common source of bugs.

To work around this problem, I suggest you use a program called the Regex Coach (pictured in Figure 15-1), available from http://www.weitz.de/regex-coach—it is free to use non-commercially, and it is able to help you check that your regular expressions are correct by visually highlighting strings that match. The Coach is fully compatible with all the options shown here, including string replacement, and can even break down a regexp and describe it in plain English.

Use the Regex Coach to try out regular expressions and get instant feedback

Figure 15-1. Use the Regex Coach to try out regular expressions and get instant feedback

Get PHP in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.