Regular Expressions_understanding

Well, I managed to complete the task. I don’t fully understand it though. I would appreciate it if anyone could help me out by pointing me to a more detailed page. furthermore, is there any good JS book for beginners?

thanks a lot

Your code so far


let text = "<h1>Winter is coming</h1>";
let myRegex = /<.*?[a-z0-9]*>/g; // Change this line
let result = text.match(myRegex);
console.log(result)

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36

Challenge: Find Characters with Lazy Matching

Link to the challenge:

Well here is a page with a lot info on JavaScript RegEx: JavaScript RegExp Reference

As to how this worked:

/<.*?[a-z0-9]*>/g
  1. < → “<”
  2. .*? → any symbol (.) zero or more times (*) with as little as possible (?)
  3. [a-z0-9]* → any lowercase letter followed by any digit zero or more times
  4. > → “>”

It’s a good idea to look at the reference as your RegEx could be optimized in several ways… as in, you literally had to do nothing but add the “?” to the original code to pass.

1 Like

Very helpful thanks so much!