Pradeep K. Pant Blog


More backtracking examples

Backtracking might be costly so one should try to avoid useless backtracking. Perl regx have  special form of parentheses: (?>…). These are called Perl’s “don’t-ever-backtrack-into-me” markers. They will tell the regex engine that the enclosed sub-pattern can safely be skipped over during backtracking. As we know that the re-matching the contents either won’t succeed or, if it does succeed, won’t help the overall match. So these markers helps to avoid useless backtracking and saves a lot of time.

Some more useful links and examples can be found at:

Perl Regx documentation page Perlre on Perldoc

Perl Best Practices by Damian Conway



Copyright © 2007-2024 PRADEEP K. PANT

Source Code | RSS