Backtracking in regular expressions

preview_player
Показать описание
Ever wondered why your regex matches too much? Or, why a regex does not capture a full value and only stores its last character? The problem is caused by backtracking, and in this video, I explain how the patterns like a.*b and a.*?b actually work.

FURTHER LINKS:
- First Look at How a Regex Engine Works Internally:
- Which one of these cases involves backtracking?
- Backtracking in Regular Expressions:
- Regex to find last occurrence of pattern in a string:
- Match up to the first occurrence of a string:
Рекомендации по теме
Комментарии
Автор

I tried to match "ab", "ab_b" and "c1_ab_b", but not "ab_pm" and "ab_pn" with the regex "ab_?(?!p)". However, my regex matched all of them. A kind person on StackOverflow told me it was because of backtracking. Your concise video helped me understand why backtracking happened in my case. Thanks very much!

CPO_