Regular Expressions in JavaScript With Indiana Jones

5 minutes to get down with regular expressions

Arnold Abraham
Level Up Coding
Published in
5 min readMay 2, 2021

--

Art made by Author with ❤

Why is there a need for such a beginner unfriendly topic?! Because you learn to validate and search text across all programming languages! That’s why!

Furthermore, you create validation patterns once and use them until infinity and beyond.

Although it is difficult to learn because the syntax looks like hieroglyphs in the Raiders of the Lost Ark, the true value lies in having this tool in your tool belt.

Motivation

As I mentioned, this is a universal tool to parse text in any programming language. A swiss army knife of coding!

Since JavaScript and Web development is great, I will show you first how to get started with JavaScript and regular expressions. Afterward, we are going to explore universal patterns to be used anywhere!

JavaScript .search / .match / .replace

Searching in JavaScript with Regular Expressions (RegExp) is easy :

This is used to find a single match and return the index. If you want more, like the greedy King Midas, then you have to use match:

You can also directly swap out the members of a string. When someone doesn’t honor your academic grade and you have to correct them, by using replace:

--

--

JavaScript, TypeScript and C#/.NET Tutorials/News/Best Practices by a German Software Engineer - Fun helps you to learn on the fly --> arnoldcode.com