How does regex decide when to backtrack?
As far I understood, on match failure, regex backtracks to the previous closest choice, chooses the next alternative and continues matching. Is it true that regex avoids backtracking, in case there is no possibility of a match ?
Here is a scenario, I am unable to explain to myself this regex101 debugger output.
Regex: ^(?
Input string: 1.222222222222.33333333333.0
Why does the above regex backtrack at the end, when there is no chance that $
will match an avoided [0-9]
? After the patch group is exhausted, will it avoid backtracking the ([1-9][0-9]*)
part for Minor and Major? If so, how and why?
If anyone has a better example to showcase how regex decides to backtrack or not, it would be appreciated.
Read more here: Source link