This website collects cookies to deliver better user experience
[week1] Days 2 - Regex !
[week1] Days 2 - Regex !
Regular expressions, often shortened to "regex" or "regexp", are patterns that help programmers match, search, and replace text. And in my dev journey I never feel like I need to learn regex, because it seemed so difficult to learn.But on my ride to complete the freeCodeCamp course i need to take this regex lessons on freeCodeCamp.
My daily code
I have done 13 of the 33 exercise, i have learned the basics of regex and find some ressources to test and getting more info on how to use it .
What did i learn ?
The basic format of a regex is like this : / expression / flags, i.e /[A-Z]+/g
You can group your expression by using parentheses (), or you can combine them by using logical OR |, it's possible to affect the search by using flags
In javascript you have multiple ways to use regex the first one is .test()
let testStr ="freeCodeCamp";let testRegex =/Code/;testRegex.test(testStr);// true
The second way is to find a matching string with
.match()
const paragraph ='The quick brown fox jumps over the lazy dog. It barked.';const regex =/[A-Z]/g;const found = paragraph.match(regex);//Array ["T", "I"]