I used to hate regular expressions, however, recently I've had a need to use them a fair amount so actually started to appreciate them. What I found challenging then was debugging them. Writing code, compiling it and executing it just to find out the regex was incorrect was not going anywhere fast, so I looked around and found Reggy.app
. This very simple app lets you put in your test strings and most importantly, your regex and see what matches. It's a super handy tool.
There are other tools out there for this kind of thing, but I find Reggy is just so simple and lightweight that it's become my regex debugging tool of choice.
Best of all, Reggy lets you see what is matching visually. The matches are highlighted for you so there is no second-guessing of what works and what doesn't.
So far I didn't really answer whether you should or should not regex, well that depends - it depends on whether regular expressions are really what your code requires, sometimes a simple string comparison is all that's needed. It's really up to you to decide, with great power [or regex], comes great responsibility :)
A quick disclaimer...
Although I put in a great effort into researching all the topics I cover, mistakes can happen.
Use of any information from my blog posts should be at own risk and I do not hold any liability towards any information misuse or damages caused by following any of my posts.
All content and opinions expressed on this Blog are my own and do not represent the opinions of my employer (Oracle).
Use of any information contained in this blog post/article is subject to this disclaimer