Skip to content

Instantly share code, notes, and snippets.

View eljayman's full-sized avatar

Leland Johnson eljayman

View GitHub Profile
@eljayman
eljayman / js-regex-comment.md
Last active January 23, 2023 03:01
JS RegEx Comment Search

JavaScript Regular Expression for Comment Search

In my studies of regular expressions (regex's) I came across an interesting use: To look for comments in JavaScript (JS). Text that isn't a necessary part of the program. Being a junior developer, I find comments edifying when looking through code. As for my own comments, I find it helpful to look again when debugging and see if I made a mistake implementing what I thought to be the right steps. And when comments as pseudocode don't make sense, what does that say about the code itself?

Summary

Whenever I search for something, odds are regex's are at work behind the curtain. So what are regex's and how do they apply to JS? Simply put, regex's are a means of searching for patterns in text. Need to validate a user's email address input before sending data to the back-end? Can I use a means to dynamically find all the URL's in a document? JS also has built-in string methods that can have regex's passed in as an argument, such as replace(), and methods