DEV Community

Discussion on: How do you feel about regex?

Collapse
 
link2twenty profile image
Andrew Bone

I like it but I tend to tell people to avoid it if possible just because it makes code hard to read.

If people on the team do use regex I ask them to include a link to regexper.com/ in a comment.

It generates a flow chart like this one.

regex flow chart

// https://regexper.com/#%2F%5E%5Cw%2B%28%5B-%2B.'%5D%5Cw%2B%29*%40%5Cw%2B%28%5B-.%5D%5Cw%2B%29*%5C.%5Cw%2B%28%5B-.%5D%5Cw%2B%29*%24%2F
const emailReg = new RegExp(/^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/);
console.log(emailReg.test('user@place.com'))
Enter fullscreen mode Exit fullscreen mode
Collapse
 
priteshusadadiya profile image
Pritesh Usadadiya

I didn't know about one. definitely useful. Thanks for sharing.

Collapse
 
baenencalin profile image
Calin Baenen

Oooh. I like this tool you introduced upon everyone.
Personally, if a regex is confusing me, I'll just pop over to regex101 for a quick test. It's also a great tool.

Collapse
 
lepinekong profile image
lepinekong • Edited

I prefer regexr.com because regex101 is not embeddable in figjam document figma.com I use to keep code notes as it supports code blocks.

Other tools I find pretty but buggy for complex regex are :

regexper.com/
jex.im/regulex
extendsclass.com/regex-tester.html

Collapse
 
andypiper profile image
Andy Piper

Now, this is really cool and useful - thank you!!

Collapse
 
jesusantguerrero profile image
Jesus Guerrero

Wow thanks for sharing that tip.

Collapse
 
lepinekong profile image
lepinekong • Edited

Have tried them all I think, that one is nice but it doesn't work for very complex regular expressions (like with some lookaround expressions) whereas it works with regexr.com

Collapse
 
internetmosquito profile image
Alejandro Villamarin

didn't know that service, seems awesome, also worth a try cucumber.io/docs/cucumber/cucumber..., makes regular expressions more human friendly and readable