Regular Expressions, Using the Test Method, freeCodeCamp's Learn Regex Challenges, 2020 Learn Regex

Lesson Summary

In this first lesson, in our mission regex journey, we learn about the test method regarding regular expressions. As discussed in the introduction video, a regex allows us to specify a pattern we are looking for. In this lesson, we create a test string that we call "'testStr". This string contains the text "freeCodeCamp". We then create our regex that we will like to search for, "/Code/". We save this within a variable called "testRegex". We then use the .test method to check our testRegex to see if it is contained within a string we specify, in this case, "testStr". If the pattern is contained within the string passed in, then the function will return true, otherwise, it will return false, indicating that the pattern was not found. In this case, it will return true, since the pattern "Code", is found within our string "freeCodeCamp".

Subscribe To Monthly Newsletter. Chance to Win Monthly Prizes

* indicates required