DEV Community

Cover image for Getting Started with Regular Expressions

Getting Started with Regular Expressions

Nick Taylor on July 18, 2021

Regular expressions (regex) are one of those things that folks seem to make fun of most of the time because they don't understand them, or partiall...
Collapse
 
mktcode profile image
mkt • Edited

Nice Article. Will there be more? Was thinking about writing a beginners guide myself.

I'd like to emphasize a bit more how tools like regextester.com regex101.com can be a great resource to learn by looking at the existing expressions or playing with your own ones and then hovering with your mouse over the expression to get an explanation of what's happening.

(btw: s missing in "Matering..." link at the end)

Collapse
 
nickytonline profile image
Nick Taylor

This was a one off, but if folks want to see more about regexes, I'd be happy to write some more about them. 😎

If you have a beginner's guide in mind, go for it! A different perspective on a topic can only be good for the community!

Also, thanks for catching the typo! I wrote this post late last night lol.

Collapse
 
cerchie profile image
Lucia Cerchie

Would love a beginner's guide!

Collapse
 
mktcode profile image
mkt

Fascinating how just one short comment like yours gets one out of procrastination and into being productive! :D

Thread Thread
 
cerchie profile image
Lucia Cerchie
Thread Thread
 
mktcode profile image
mkt • Edited

dev.to/mktcode/regular-expressions...

I found there are already so many good resources for technical people, so I tried to write something specifically for non-technical people. Hope it works.

Collapse
 
samuelroland profile image
Samuel Roland

Hey
Thanks for the article! Great introduction!

I wanted to write it on it because I struggled to understand it at the start, but didn't how to start because it's pretty broad subject (to understand I had to learn several not intuitive concepts and make a lot of tests). Now I have some good basics. I didn't know the "+?" combination trick that's great.

The app that helped me a lot (and that you can maybe add to the resource list) is regexr.com (it's opensource!). You can even save your patterns (like this one, publish and browse existing patterns, read a cheat sheet, and the colours and interface really help to understand. I really like the "explanations on hover with selections".
Another websites that looks fun learn-regex.com and regex-one.com.

A few suggestions to enhance it:

  • Explain the goal of regex (like search, validate or replace strings).
  • To say or give example on how to run regex (depends on the languages is important to mention too).
  • Add some examples for simple password validation.
  • Mention that often there is no need to write complex Regex for common use cases (such as email or validation) because they already exist (just need to search and choose one, especially for email where there is no perfect regex AFAIK). Sometimes they are constants or functions that already exist in languages to validate them.
Collapse
 
nickytonline profile image
Nick Taylor

Thanks for the feedback Samuel!
BB-8 giving a thumbs up

Collapse
 
link2twenty profile image
Andrew Bone

I quite like Regexper you paste in a regex and it turns it into a nice railroad diagram.

Collapse
 
nickytonline profile image
Nick Taylor

Thanks for the share Andrew!

Collapse
 
alexkapustin profile image
Oleksandr

Didn't read all, just till:

const reMatchThree = /(?:\s|^)(three)(?:\s||.|,|;|:|'|"|!|"|'|$)/g

Why don't you simply use:

const reMatchThree = /\b(three)\b/g

?

Collapse
 
nickytonline profile image
Nick Taylor • Edited

I completely forgot about word boundaries while I was writing it late at night lol. I’ve updated the article. Thanks for this. 😎

Collapse
 
mccurcio profile image
Matt Curcio

GREAT Intro!

Collapse
 
priteshusadadiya profile image
Pritesh Usadadiya

[[ Pingback ]]
This article was curated in #17th issue of Software Testing Notes .

softwaretestingnotes.substack.com/...