DEV Community

Discussion on: Making Regular Expressions Readable in JavaScript

Collapse
 
jonrandy profile image
Jon Randy πŸŽ–οΈ • Edited

So you want to slow your code down for the benefit of perceived readability for people who aren't so good at regex? This would be something better done at build time

Also, if you really want to do it right there in the code, you could make the syntax a lot nicer by using a tagged template:

reggie`commented regex here`
Enter fullscreen mode Exit fullscreen mode
Collapse
 
rfornal profile image
bob.ts

Tagged Template Literal is now included.

Also, there are plans to incorporate this within build tools.

Collapse
 
rfornal profile image
bob.ts

The slowdown is negligible. If used in a service or class, the regex can be generated once.

As to people who β€œaren’t so good at regex,” I always write my code with the assumption that someone else has to figure out what I did and if I can make readability easier, I should. That is what the whole project is about.

Tagged template: hadn’t thought of that. I’ll look into it.

Thanks!