There seems to be a shared struggle when it comes to Regular Expressions. Some suffer readability, some think it's completely useless, others find it difficult to learn. What do you think? What are struggles you face with Regular Expressions?
For those with no problems with it, what would you give as advice? What helped you grasp them?
Top comments (4)
regex101.com <- that is without doubt one of, if not the best ways to learn Regular Expressions.
I think the issue is that they look complicated and it is really easy to make a mistake, a tool like the above breaks down the steps you have written, explains them and lets you test against some text so you can check it matches.
Also a lot of people get confused because they try and use regular expressions to parse HTML....your will always end up in a mess with that! (if you have never seen the famous StackOverflow post on using a RegEx to parse HTML then follow that link!)
I mean, they also look horrible sometimes and I think that makes people think they use some kind of voodoo to work....
That right there is a regular expression to parse Markdown as part of a library called snarkdown, and it kind of works! (it might not display well on dev.to comments due to the fact it contains a load of markdown but you get the idea!)
But trying to get your head around it requires breaking it down into tiny sections, in which case it isn't so scary (but still difficult!)
Above all - get into developer mode when writing a RegEx - break the problem down into tiny steps and tackle each one at once.
For me is that I've used them only in rare instances so that every time I need to relearn the syntax.
The fact that I have to keep referring to the documentation because I have not learned it fully π
Without a doubt the best regex cheatsheet ever... I never leave home without it! π