Intro to Regex for Web Developers

Chris Achard on October 08, 2019

This was originally posted as a twitter thread: https://twitter.com/chrisachard/status/1181583499112976384 1. Regular expressions find ... [Read Full]
markdown guide

I have looked so hard and long the past year for an explanation of regex that I would understand and this is the first one that put everything I need to know together.

I really love the format of examples of how to use the theory you mention, so I can see how it will work, since most explanation either show the theory or just a bunch of examples.


Glad you liked it! Yeah, it turns out regex is really complicated, heh... there are so many little rules - it's like its own little language all smushed together into a single line :)


Indeed the examples where the killers. You nailed it @chris


I recommend learning Regex if for no other reason than pulling off complex searches (and search and replaces) in code editors. A few Regex tricks can turn an otherwise tiresome "find, check, and replace in all the files" to an automated search and replace function. Great to see more content helpers coders get to that point!


Yes! This is probably my number one use case as well; that, and trying to extract data from HTML or other messy data 😯 which I know, I know, isn't a good use case (I even say so in the post!) but for one-off tasks it's really powerful.


I'm glad I found this one. Finally it's possible for everyone to understand regex :D I like your summary, Chris.

I can recommend this tool/website for testing and building regex. It helped me a lot: regex101.com/


Great! Glad it helped.

That's a nice site - thanks for the link!


Great building up of the level of the regex's!
I kinda started my regex knowledge from regular-expressions.info/, the guys that also made RegexBuddy. Very detailed and with a lot of simple examples.

And if you really want to get a feeling for regex's, try regexcrossword.com/.


I like Regex since I tried to create a validator for checking my identity card in my country back in the day.

I think it is worth to mention that there are multiple variants of Regex implementations like the one in Perl, Linux or PHP I think.

Thus it depends on the developer. It might make sense to adopt certain variant of Regex to get what you need.


Yes, that's a good point. The major points are the same across languages, but there are some differences (how the flags behave for example) - so if you're using the more advanced features, then watch out for cross language differences.


Great read Chris!

One resource I found super useful, once I dove into regexes more was the Mastering Regular Expressions book. I have the 2nd edition, but there appears to be a 3rd edition out.

Looking forward to your next post!


Thanks! While writing it I realized that regex is just really complicated πŸ˜… I had trouble distilling it down into a single "intro" post.

I do have ideas about a page with real examples and explanations though that I think will help - so I'm working on that :)


Yeah I often have those ideas where I think "okay I am just going to make it easy and understandable" and then "why the heck has this to be so complicated" :)


Regex has always been something which is hard to grasp(atleast for me)....
This post proves it to be wrong.

Excellent Post Chris.


Glad it could help!

Yeah, it's often disheartening to see really complex regexes and get totally lost... but just a few basics can get you pretty far!

I still get lost in really complex regexes though πŸ˜‚ especially when they start involving capturing groups or lookahead, etc.


This is the best REGEX explanation + examples I have ever came across on the web!

Thank you!!


Very nicely explained. First time to understand what Regex is about. Thanks.


Just a note, under part 8, your escape sequence seems to have been escaped into just a single *, so its missing the backslash now.


Oh, whoops! Good catch... turns out markdown will take \* as an escaped *, so I needed double backslash there. Thanks!


This is what i always wanted <3. Tried hard in the past to understand regex and this did the work!


I am using regex for years and still im like "i have no idea what im doing" in it. Regex is really hard to master. Thank you.


Yes, it is for sure :) I still am not good with lookaheads, etc... but thankfully regex is still really useful even with just the basics!


Great summary for beginners, good job! πŸ˜‡


What a great post. I am saving this for the future and sharing it with my colleagues. Thank you!

code of conduct - report abuse