
stackoverflow.com
https://stackoverflow.com/questions/52241122/why-d…
regex - Why does a*a match aaa? - Stack Overflow
It does initially attempt to match the entire string, but repetition will backtrack if a match fails. After the a* initially matching the entire string, the regex tries to match the next token, the single a This fails, so then the a* backtracks back a character (so that it only matches aa rather than aaa). This time, the last token, the single a, is fulfilled, so a match is found. Greedyness ...