Find More Than the First Match, freeCodeCamp's Regexes Tutor, Regular Expression Help 2020

Lesson Summary

In this lesson, we continue looking at regexes. In previous lessons, we learned how to see whether a pattern exists within a string by using the .test method, and we also learned about the .match method which allows us to return a pattern when it is found. Flags have also been explained in previous tutorials, and today we look at finding and returning every time our pattern is found using the "g" flag. The "g" flag for a regular expression allows us to find every instance of our pattern within some text, not just the first time it is found. We are able to combine this flag with the "i" flag we recently learned to ignore casing. If we combined both flags we would essentially be returning all instances of a pattern found regardless of casing.

Subscribe To Monthly Newsletter. Chance to Win Monthly Prizes

* indicates required