Intro to RegEx

Gage Thornberry
2 min readMay 11, 2020

What is Regex?

“Regular expressions are patterns used to match character combinations in strings. In JavaScript, regular expressions are also objects. These patterns are used with the exec() and test() methods of RegExp, and with the match(), matchAll(), replace(), search(), and split() methods of String.”

-W3 School

There’s a lot of information here. RegExpressions are made by creating patterns to filter out strings/data that you want, and in doing so, creates a new object for each instance of the expression.

Regular Expressions are useful because you can dynamically filter data out of strings and organize it however you would like. RegEx also offers a few different built in methods for testing data, replacing and modifying data in place.

What is Regex Used For?

RegEx can be used for string validation in front/backend web development, and is most commonly used today for Web Scraping. This can be done simply by making a request to the static HTML page that you want data from, and formatting/filtering out the information you do want and don’t want. There are other uses for regex but from what I’ve seen this is the most applicable use for development.

How can you use regex?

So like we talked about earlier, JavaScript offers a few different methods for validating and filtering data with RegEx.

regex.test()

The one I’m most familiar with is the test() method. Plug your sting into the regex.test(string), and it will return true or false based on what you’re testing for. This is extremely useful for finding certain data inside of a large string. It also comes in super handy for things like code challenges. Next blog I will get into the other methods that can be used in JavaScript and other languages that support it. Thanks for reading.

--

--