In years of being a developer I never really spent the time to learn regular expressions. It always seemed like a hard nut to crack.
I used to spend so much time trying to find regular expressions for my use case.
now you have two problems
Enter iHateRegex.io
I made a simple tool that will explain to you commonly used regular expressions work.
It is a simple tool that will show a visual graph as well as matches and highlighting for code.
Hope you like the tool :D
Tech
Public Repo: https://github.com/geongeorge/i-hate-regex
The application is built using:
- The awesome Nuxt.js framework
- Tailwind.css
- for the visual demo I used: https://gitlab.com/javallone/regexper-static
Update
- Thank you for all the love and support guys π Posting this has given me enough motivation to work on this more.
- The application is just an MVP right now. With the support of everyone, I can make this into a great project for beginners.
- I'm also working on tutorial pages to get started on regex. here's a sample
Producthunt launch
I just launched iHateRegex on Producthunt πΊ
ππ
https://www.producthunt.com/posts/i-hate-regex
Top comments (89)
The main problem with regex is that they overused.
For simple problems, regex are not needed, you have simpler, more readable solutions.
A combinaison of
split()
,subString()
,removePrefix()
,removeSuffix()
is usually enough.For complex problems, regex are not good at all.
Do not use a regex try to parse email, or URL, or HTML, ...
If the regex is not trivial, do not use a regex.
My advice:
Have a rule for pull requests that insists that every regex must come with a unit test that includes input that the regex is supposed to match and the ones that it's supposed to reject.
I used to feel the same.
Then I actually learned how to use regex.
Now I think that non-regex solutions that use more than one function are better done with regex. Because 80% of the time you only need simple regex patterns.
(Almost) totally agree.
Will do <3
I agree about the part where people shove in regex where it's absolutely overkill.
I very agree with this!
To pre-validate, you can keep it simple like this:
Delightful tool. Bookmarking!
I also hate regex, so much that I'm helping design an expression parser that addressees many of its flaws. This new parser won't replace regex β trying to be everything to everyone is how it came to be so annoyingly esoteric to begin with β but it'll hopefully be better than what we have for a number of common cases.
Thank you.
Your parser would be amazing. If it plugs into javascript I really would love to try it out.
I'm implementing it for our C++ game engine, so this implementation won't be Javascript compatible. That said, both the code and the specification will be open source, so there's nothing stopping you (or anyone else) from implementing it elsewhere.
is it already under construction? I'd love to see the repo
We're fairly early in the implementation stage β the code is currently under a serious breaking refactor β but you certainly check it out. The project page is here, and you can follow our development on Phabricator.
This looks cool
I really wanted a parser built like regex101 for my tool. Really don't know where to start
github.com/geongeorge/i-hate-regex
I have been a programmer for over a quarter of a century. And I used to think that I would never "get" regular expressions. Then one day about 6 or 7 years ago I realized I could write regular expressions correct about 80% of the time, after which it occurred to me that I now "get" regex. What changed?
I started using PhpStorm (or any JetBrain's IDE) and forced myself to use regular expressions to do search and replace. Because of how their UI works β itΒ includes a preview of the result for each occurence when it asks if okay to replace βΒ it basically trained me to grok regex.
So, trying to learn regular expressions only when you need to use one in your code will, if you are like me, leave you forever unable to become one with regex. But if you would like to learn the 20% of regex like the back of your hand that you'll use 80% of the time, grabbing a JetBrain's IDE (or maybe some other IDEs or text editors) and forcing yourself to use regex on almost every search is really all it takes.
#jmtcw
Thanks for sharing the story Although I didn't use any special ide other than vscode, building ihateregex.io made me understand a lot of it. I can build my own expressions now.
@bpedroza
You have a good point, which will allow me to refine my position.
I think that we should stop over focusing on the HOW you did the pattern matching part (oh see, a nice regex! let me make it even better) and focus more on the WHAT it's supposed to do and WHY it's important.
Having the unit tests for the regex allows to reframe the question this way.
Then it's an implementation detail whether you use a regex or a parsing library or whatever, and I am fine with all of those solutions.
You really did a great job at self-improvement here, even if it wasn't your intention at first! :)
Take a problem, solve it and overcome it.
What I like especially about your site is that you are greeted with a couple of popular choices and just a searchbox to get started. On other sites I always find myself getting lost in information like tips, setting options, understanding different flags and stuff that is visible right after loading the page.
The clean UI helps to stay focused on getting the regex and leaving again.
Thank you for the coffee and the feedback <3
I'm happy to see you liked it
This is a nice, clean resource, with a great little graphical description system. I like it.
It's different to all the other regex pages because they're geared around you typing things in and testing them, where this is a "tl;dr" of sorts.
I don't understand why people don't like regex though. It's kind of like saying you don't like arrays.
Thank you. I like clean as well; clean is good.
In my case, I just put a clickbaity url so people would actually look at it and I thought it's funny..lol
PS: I'd love if you put this review on product hunt. This is my first launch there. producthunt.com/posts/i-hate-regex
Many people forget that you can use multiple regex pattern for one input. While everybody knows that a function for everything is bad and you should write one function for one purpose, everybody still writes regexes that include everything in one command. Maybe it's time to write an article on encapsulation of regex?
according to your regex, this is a valid emailaddress: geon@ihate@regex.io
I have 2 email expressions in the app(try a search). Just use the simple one if you don't know what you want. It works 99% of all the time.
If you wanna get it 99.9% success rate use the complicated one (but please don't)
read the comment thread in this post by @hyftar and me
I see. Well, I just clicked "email" on the homepage and I landed on the simple email :-)
With the complicated email, I think you need to consider word boundaries, since you match a part theproblem@test@gmail.com , but it should be entirely right or entirely wrong.
I'm starting to see why you hate regex ;-)
π Yeah. I will spend some time to properly understand the email part
Any suggestion?
bookmarked
Thank you <3
Some comments may only be visible to logged-in visitors. Sign in to view all comments.