DEV Community

Geon George
Geon George

Posted on

I hated Regex so much that I made iHateRegex.io

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

https://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:

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

Oldest comments (88)

Collapse
 
jofinjohn123 profile image
Jofin

Ooh i really liked your tool,why don't you make more like this?

Collapse
 
ajayrajgvr profile image
Ajay Raj K

Thanks brother.. i hate regex too..nice share for people like us

Collapse
 
geongeorge profile image
Geon George • Edited

:D Haters assemble!

Collapse
 
hyftar profile image
Simon Landry

Where does all this hate for Regex come from?? I never thought it was complicated and learning it can be done within a few hours.

Collapse
 
geongeorge profile image
Geon George

it comes from fear and lack of clarity.
Take the case of a simple expression to validate an email:
emailregex.com/
Why does it have to be this hard?
even if you check any stack overflow thread you'll find 100s of opinions.
stackoverflow.com/questions/46155/...

(read that again imagining you are a beginner)

Collapse
 
hyftar profile image
Simon Landry • Edited

Well simply put, Regex is not the right tool for validating email addresses and should be only used as feedback on the frontend of your app. If the patterns you're using get this complicated, it's probably a sign the thing you're using it for isn't the right task for the tool (and considering the amount of people in the comments of your website that are finding all sorts of edge cases, I think this is accurate).

Of course if you want to do things right, it often gets really tricky, but that's like showing the code base of a huge website as an example to someone who wants to learn a programming language, of course he's going to be overwhelmed and will feel defeated, but no one should start with the complicated stuff.

Regex at its core is fairly simple, but sadly, it's often overused and misused.

Thread Thread
 
geongeorge profile image
Geon George

Regex at its core is fairly simple, but sadly, it's often overused and misused.

That was one of the main reasons why I started this idea. It's a simple cheat sheet for commonly used regular expressions.

Also, I don't really hate regex (hypocrite me πŸ˜‚). The name is just a funny thing I came up with. I've seen a lot of hate for this online.

I hope the idea became clear when you opened the website. It's not a rant about how many people and I hate the thing.

PS: If you ask me the only email validation expression that I might ever use with regex is this: ihateregex.io/expr/email

Thread Thread
 
hyftar profile image
Simon Landry

I completely agree with the email one, that's also the one I went with in most of my projects. I convinced some teachers in the past that Regex is not the best tool for email validation and that we should use that pattern in frontend instead.

Also I figured you didn't actually hate the thing if you created a whole website about the thing πŸ˜‚πŸ˜.

You've done a good job of explaining it, although some patterns (such as the IP one) could probably be simplified a bit.

I'll definitely forward your website if I see someone struggling. Great job!

Thread Thread
 
geongeorge profile image
Geon George

Thank you. I need to improve the explanations as well. (Will fix those :) )

at some point, I really felt embarrassed to share this.
It's been sitting in my Github for a while and I finally decided to share and see what everyone else thinks about it.
Your feedback has been of great help :D (there is also a beginners tutorial article in the making)

Thread Thread
 
hyftar profile image
Simon Landry

If your repo is public, I'd be glad to help with a PR or two! 😊

Thread Thread
 
geongeorge profile image
Geon George

Here you go 😊:
github.com/geongeorge/i-hate-regex

The code is not the most elegant (I have to warn you)

Thread Thread
 
iamschulz profile image
Daniel Schulz • Edited

Regex is not the right tool for validating email addresses

Huh. I always do complex stuff like this with regex, in frontend as well as in backend.
What would be your tool of choice?

Thread Thread
 
hyftar profile image
Simon Landry • Edited

Depends on the language, in PHP for example, there's this library: github.com/egulias/EmailValidator

Basically, since there are so many rules and edge cases about emails, creating a Regex to solve that problem is not a productive approach since if new edge cases are created or found, maintenance instantly becomes hell and the pattern most likely has to be recreated from scratch.

Fortunately, people have already poured tons of hours into solving that problem for us and we can build on their shoulders.

Another example where regex looks like an appropriate tool but isn't is with parsing HTML. It sprung a famous Stack overflow question answer.

Thread Thread
 
geongeorge profile image
Geon George

I just launched iHateRegex on Producthunt 😺

πŸ‘‰πŸ‘‰
producthunt.com/posts/i-hate-regex

Collapse
 
theodesp profile image
Theofanis Despoudis • Edited

The problem with Regexes (especially the complex ones) is that they are really prone to errors so you have to write tons of tests to verify them. But who wants to write a million tests? We just copy and paste from stack-overflow or use a trusted library and pray for the best. That's why they have a bad reputation.

Collapse
 
geongeorge profile image
Geon George

to point! I like it <3

Collapse
 
devanghingu profile image
Devang Hingu

for newbie, it too complicated. when write regex only for email and username, it cool. But when it going with complicated stuff. me also sometimes stuck with it and hate it. but at end of i like it...!! because i m also programmer. :D. i have no else option. :)

Collapse
 
geongeorge profile image
Geon George

;) aren't we all

Thread Thread
 
devanghingu profile image
Devang Hingu

yeah..!!

Collapse
 
diyaliza profile image
Diya Liza Varghese

Great thing that you came up with something this useful when a lot of people still hate all the complexities behind regex. So, does ihateregex help to generate regular expressions with a set of strings?

Collapse
 
geongeorge profile image
Geon George • Edited

not in its current form. It just allows you to edit and play around already saved expressions

Collapse
 
cemkaanguru profile image
cem kaan kosali

bookmarked

Collapse
 
geongeorge profile image
Geon George

Thank you <3

Collapse
 
eyarz profile image
Eyar Zilberman

🀩 This is awesome!
How can I contribute more builtin patterns?

Collapse
 
geongeorge profile image
Geon George • Edited

Thank you <3 ! Right now there is a google form on the website.

You can also send a pr: github.com/geongeorge/i-hate-regex

Just add your regex to static/regexdata.json

(excuse the bad code. will slowly fix that :P)

Collapse
 
natriumdev profile image
NatriumDev

according to your regex, this is a valid emailaddress: geon@ihate@regex.io

Collapse
 
souksyp profile image
Souk Syp.

Any suggestion?

Collapse
 
geongeorge profile image
Geon George • Edited

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

Collapse
 
natriumdev profile image
NatriumDev

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 ;-)

Thread Thread
 
geongeorge profile image
Geon George

πŸ˜‚ Yeah. I will spend some time to properly understand the email part

Collapse
 
geongeorge profile image
Geon George

Thank you <3

Collapse
 
sm0ke profile image
Sm0ke • Edited

Nice service, Regex works nicely on simple things.
Thanks for the link - you deserve at least a Github * for your efforts.

Collapse
 
geongeorge profile image
Geon George • Edited

Github stars are much appreciated -^ Thank you

Some comments may only be visible to logged-in visitors. Sign in to view all comments.