this post was submitted on 10 Oct 2023
16 points (100.0% liked)

JavaScript

2004 readers
1 users here now

founded 1 year ago
MODERATORS
 

I am currently trying to learn Javascript and am getting hung up trying to understand Regex. Does anyone have any good resources or recommendations for me?

top 10 comments
sorted by: hot top controversial new old
[–] [email protected] 15 points 1 year ago (1 children)
[–] autokludge 3 points 1 year ago

also sometimes handy to show railroad diagram to help visualize the pattern.

[–] Ategon 6 points 1 year ago* (last edited 1 year ago) (1 children)

regex101 is great for building up regex expressions

weve also got a regex community in the instance at [email protected] with some stuff in it

[–] [email protected] 1 points 1 year ago* (last edited 1 year ago)

The most dangerous community

(Sanitize your inputs, kids)

[–] Sparrow_1029 4 points 1 year ago

https://regexlearn.com/ is interactive to get you started.

Then try reading maybe the python regex docs for more detailed info. There are multiple flavors of regex as well, which makes it even more confusing (yay), but you'll eventually grok it enough to make it a part of your toolbox! I use simple regex frequently for search/replace (VScode or vim), and in the shell.

For more complex string parsing operations, there's often a faster/better method than regex, but it's really good to know.

[–] CameronDev 4 points 1 year ago

This isnt really a resource as such, but an interesting game that effectively nerdsniped my whole team:

https://rampion.github.io/RegHex/

[–] thisisnotgoingwell 1 points 1 year ago

There's a lot of great resources others have given, but as an overview, regex is kind of a mini language for Natural Language Processing. If you work in any kind of field where you have to work with unstructured data that contains things like phone numbers, names, IPs, hostnames, DNS records, etc, it's a very powerful skill to have. Regex is for the most part largely the same across different languages, so if you learn regex for Python or JS or Perl it's largely the same.

The power comes from using regex meta characters. You'll have to look them up a lot to remember what they each do... You will probably have to reference a meta character guide pretty often at first, so it might be a good idea to print out a cheat sheet.

Learning regex was the start, for me, of being able to write applications that could easily be reused.

[–] [email protected] 1 points 1 year ago

If you like videos then I think this video is quite decent: https://youtu.be/rhzKDrUiJVk?si=UUfyL5ua7FGnGJsL

[–] Paragone 1 points 1 year ago

I just discovered that Exercism.org doesn't have a regex track...

Well, I'll be...

: )

[–] [email protected] 1 points 1 year ago

RegexBuddy is an oldie software that gives you all the tools you'd ever need for working with regex. It has a wonderful tutorials section which I have found very interesting despite my years of experience in the subject! In practice I've been using Regex101 for years and with the introduction of an actual debugger it's feature complete, as far as I'm concerned. But I'd still recommend checking out RegexBuddy material. Very deep stuff.