
The problem with regular expressions is that they are too powerful, hence often mistaken for a Parser + Lexer and therefore lead to code which is VERY HARD TO MAINTAIN.
Please devs, when you need to match a c struct - use ANTLR or whatever and avoid what I did back in the day:
/((\w+\s*(,\w+\s*))(\n|\s))?{([^}])}(\n|\s)(\w+\s*(,\s*\w+\s*)*)?;/g 🤪
(ps: it’s only one of many, yes it might have bugs, no I did not find them yet, no it’s not in production anymore..)
Top comments(9)

- Email
- LocationGermany
- WorkSenior Frontend Developer at CrabNebula
- Joined
Regex is a simple yet powerful concept, comparable to a hand gun - and as easily abused to shoot oneself in the foot. There are valid uses for it, and a lot more invalid ones. But don't be too harsh on yourself. If all you have is a hammer, everything starts to look like a nail.

- LocationKarlsruhe, Germany
- WorkCo-Founder at Codesphere Inc.
- Joined
Agree!

- LocationAthens, Greece
- Joined
Terminal and programming languages have some form of regex already, whereas antlr is something you have to install and you still need comments anyway:
github.com/antlr/grammars-v4/blob/...
Regex can be written in multiple lines with comments, clear commit messages and tests.

- LocationKarlsruhe, Germany
- WorkCo-Founder at Codesphere Inc.
- Joined
Sure, nothing bad with regex for small things like matching an email, version number or similar.
Just not the best IDEA to treat it as a real parser :)

- LocationFollowing opportunities (currently in Mexico)
- EducationMasters, Engineering Degree
- WorkSoftware Engineering Leader
- Joined
Use tokenizers

I always use regexr.com or regex101.com 😉
Based on the rarity I need it, never even consider to learn it fully 😀😀

- LocationKarlsruhe, Germany
- WorkCo-Founder at Codesphere Inc.
- Joined
I still use them! It is valuable to be good at regex, especially for one-time tasks where you want to reformat some data :)

- Email
- LocationNY
- EducationMount Allison University
- PronounsHe/him
- WorkCo-founder at Forem
- Joined
Can you explain ANTLR?

- LocationKarlsruhe, Germany
- WorkCo-Founder at Codesphere Inc.
- Joined
"ANother Tool for Language Recognition" - It is a parser generator :)
You can use it in similar ways to regex but it is meant for bigger tasks (like detecting a c-struct) and it can also detect and locate errors.
Every programming language uses a parser to interpret the code or translate it to machine code.
Fun fact: Some parser generators even use regex to create the lexer, which is responsible for splitting the input into tokens.
For further actions, you may consider blocking this person and/orreporting abuse