I understand the principle of greedy and lazy operators, but I don’t understand how does the global tag come into play when using a greedy operator.
In the regex section ’ Find Characters with Lazy Matching’, the regex /t[a-z]*i/ will match ‘titani’ in the string ‘titanic’. WHY? There’s no global operator to tell it to search the whole string. What if I’m just looking to find the first case that matches the pattern?
Also, the inclusion of the global operator doesn’t make the pattern find all the matches!
So for example:
let greedyString = "titanic";
let greedyRegex = /t[a-z]*i/g;
let result4 = greedyString.match(greedyRegex);
alert(result4)
The result won’t be ‘ti, titani’, as I would expect, but only ‘titani’. What’s going on here?
Much obliged,
Ivan