Regex help

Regex help

I struggle a bit with regex -- like I've said before. I speak regex, but I'm not fluent. It's something I'm working on. Today I ran across a couple sites that really help and I wanted to share them.

The first breaks down a regex statement visually. The second does it in words.

So on Advent of Code day 4 we had this regex to pick out hex color codes.

^#(?:[0-9a-fA-F]{1,2}){3}$

Looking at that visually, using https://www.debuggex.com/ we see:

Screenshot 2020-12-09 at 19.23.44.png

The second site https://regex101.com/ gives this explanation:

Screenshot 2020-12-09 at 20.53.41.png Nicely explained, step by step.

As another example, here's a regex that picks out phone numbers.

/((\d{3})(?:\.|-))?(\d{3})(?:\.|-)(\d{4})/g

Check it out in visual form:

Screenshot 2020-12-09 at 20.46.56.png

These are great tools that I'm going to keep handy. Regex is already starting to feel less foreign.