Regular Expressions: Find Characters with Lazy Matching challenge

What exactly does a lazy match do ?
Why does
"titanic" matched against /t[a-z]*?i/ returns "ti"
but
"<h1>Winter is coming</h1>" matched against /<.*?>/ returns "<h1>" instead of <> just like the above code
Does lazy match ignore non-definite quantifiers or it just do whatever it likes

A bit about regular expressions:

 . means "any character"
 * means "zero or more times"
 ? means "as little as possible"

returns "<h1>" instead of <> just like the above code

There is no slice in the string “<>” so ofcourse the match cannot return it.

Ok I get it for the second regex , but then why didn’t /t[a-z]*?i/ on "titanic" return "tiic" but it ignored everything in [a-z]

You don’t understand how .match works ^^°
It looks for a slice of a string that fits the regEx. It does NOT stick together letters that are not directly next to eachother. The word “titanic” does not contain “tiic” → so it cannot return it.
What it does return is a string that starts with a “t”, ends with an “i” and has zero or more (*) lowercase letters ( [a-z] ) inbetween BUT as little as possible (?) - which includes said zero. The first time this condition is true is with the very first two letters in the word “titanic” → ti
Meaning it ignored everything in [a-z] because you specified it could.
The symbol for “at least one” is “+”.

It is also impossible for the match to return “tiic” because you specified it should end with an “i” and “tiic” doesn’t. Please inform yourself again on how regEx functions work, if you have trouble understanding this :wink:

1 Like