Just a little something that I am having trouble understanding.
I took the example from the instructions to codepen.io so I could mess around with it a bit to make sure I was grasping the concept properly of the
? character when lazy matching.
I began moving around the
? character to see what would happen and when I moved it to the end of the regex I thought there would be no difference in the match, but instead it returned “titanic” rather than “titani” .
I can only assume that the
? character stops after matching the character behind it ?
let ship = "titanic"; let regex = /t[a-z]*i?/; // why does this return "titanic" instead of just "titani" let result = ship.match(regex); console.log(ship.match(regex))
Also I might add this came up because my solution to the lesson itself was :
let myRegex = /<h.?1*>/; //but It also accepted this : let myRegex = /<h.1*?>/;
which led me to believe it made no difference where I put the