10. Regular expressions are everywhere
Here's a short list of programming languages and tools that support regular expressions. The links are to their regex documentation.
- The .NET Framework
- ActionScript
- ColdFusion
- Java
- JavaScript
- Perl
- PHP
- Python
- Ruby
- Tcl
- Apache HTTP Server
- Google Analytics
- Google Code Search
- Yahoo! Pipes
- Microsoft Exchange Server
- Windows PowerShell
- OpenOffice.org
- Oracle Database
- Any decent programmer's text editor or IDE
- And thousands more…
9. Regular expression mastery can help you stand out from the crowd
Regular expressions might be everywhere, but many experienced programmers are intimidated by them. Knowing how to use regular expressions effectively is a valuable skill that can quickly make your peers take notice.
8. Wielding regular expressions can make you feel like a mighty wizard
Regular expressions can be difficult to master, but doing so is that much more rewarding as a result. Writing a line of cryptic letters and symbols that does what might otherwise take hundreds of lines of code can feel pretty cool.
7. If your search is simple, regular expression syntax is simple
Want to match the word "cat"? The regex is simply cat
. ^cat
matches "cat" at the beginning of the string, cat$
matches at the end, and cat|dog
matches "cat" or "dog". Most regex syntax is very simple once you get the hang of it.
6. Regular expressions are portable
That's a bold lie, yet it's usually true for people who stick to the basics or intentionally write their regexes in a portable way. The majority of regex syntax works the same in a wide variety of programming languages and tools.
5. Regular expressions can help you write short code
This can be especially helpful in JavaScript, where keeping code length down is important for people with slow Internet connections. And although regexes can be hard to read, I'd rather spend a minute stepping through the logic of a regex than doing the same thing with a page full of code. Of course, like with most things in life it's important to find a good balance.
4. Regular expressions save time
Even for newcomers who still struggle with the syntax, regular expressions are often the fastest way to get the job done.
3. Regular expressions are fast
Although typical backtracking regex engines have so-called pathological cases which can take a very long time, regexes written with performance in mind will be fast enough for your needs in almost all cases. To ensure that's true, it's a good idea to at least get a feel for the basics of regex performance optimization.
2. Regular expressions can match just about anything
In other words, regular expressions are powerful. A regular expression guru can find many appropriate uses for regexes where the untrained user might not think to look. As the authors of Programming Perl wrote, "if you take 'text' in the widest possible sense, perhaps 90% of what you do is 90% text processing."
1. Regular expressions are fun
Like any good challenge, regexes can be a lot of fun. Tools like RegexPal can help remove a lot of the guesswork, so you can concentrate on solving problems.
… Feel free to add your own reasons why you think regexes are awesome^2 or the worst idea since unicycles.
Update: This post has been translated into Portuguese (by Fábio Luciano) and Spanish (by Fernando Briano). Thanks guys!