Https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures-v8/learn-regular-expressions-by-building-a-spam-filter/step-35

Hi

I am stuck at this. Not sure what is wrong when i check this on chrome console app using regex test method it returns true for “dear friend”. I am getting Your dearRegex should use a character class to match i , 1 , or | . Please help.

Many Thanks,

const dearRegex = /(?:^|\s)d[e3][a@4]r fr[i1\|][e3]nd(?:$|\s)/i;

Hi @djstaples1

Here’s an article you may find helpful.

Happy coding

1 Like

Thanks but that’s what I have done in the first place and still not working.
I even posted your solution still not working. Am i doing something wrong here.

const dearRegex = /(?:^|\s)d[e3][a@4]r fr[i1\|][e3]nd(?:$|\s)/ig;

I didn’t post the solution. I posted the problem in your code.

The solution is in the article.

1 Like

I thought character we would need to use character class as using | normally indicates “or.” Very interesting how regex can identify between “or” and whether you want to exactly search for the | character without char class escape. All sorted now. Thank you very much.

1 Like