Skip to main content Accessibility Feedback

Regex with JavaScript

Regular expressions, or regex, are patterns you can use to match specific characters in a string.

For example, let’s say you have a set of strings that look like this: id-num-{some id}-abc. You want to get the value of {some id} from inside that string.

Regular expressions provide you with a way to match those characters and extract them from the string.

Regular expressions are notoriously hard to write, and in particular, to write well. They often have unintended side effects or miss specific patterns.

There’s an old quote from programmer Jamie Zawinski about regex:

Some people, when confronted with a problem, think “I know, I’ll use regular expressions.” Now they have two problems.

There are often other, better approaches to solving the same problem. That said, sometimes a regular expression really is the best option.

Today, I wanted to share two videos from Steve Griffith that dig into writing regex with JavaScript.

First, an intro to regex.

Then, a look at practical uses of regex in JavaScript.