A regular expression assistant

Although there's 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 an online site such as Regex101.com, which helps you check your regular expressions are correct by visually highlighting strings that match. It's fully compatible with all the options shown here, including string replacement, and can even break down a regex and describe it in plain English.


Want to learn PHP 7?

Hacking with PHP has been fully updated for PHP 7, and is now available as a downloadable PDF. Get over 1200 pages of hands-on PHP learning today!

If this was helpful, please take a moment to tell others about Hacking with PHP by tweeting about it!

Next chapter: Checking whether a function is available >>

Previous chapter: Regular expression syntax examples

Jump to:


Home: Table of Contents

Copyright ©2015 Paul Hudson. Follow me: @twostraws.