DEV Community

Black-Thor
Black-Thor

Posted on • Updated on

[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.


Garabato Kid meme

Garabato Kid


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
Enter fullscreen mode Exit fullscreen mode

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"]
Enter fullscreen mode Exit fullscreen mode

Common Regex symbol or flag

Symbol Meaning
i flag the search is case-insensitive
g flag the search looks for all matches
* Match 0 or more characters
+ Match 1 or more characters
[abc] Any of a,b or c
[^abc] not a,b or c
[a-z] Any letter from a to z
[a-c2-8] Any letter or number from a to z or from 2 to 8

Usefull Ressources

Thank you for reading this post, hope you loved it 😀

PS:

  • if you see any spelling or grammar mistakes, can you notify me (I am still improving my English) ? thank you !
  • if you have any tips for improving my post feel free to comment on the post

Top comments (0)