What does it mean to use a regular expression backtracking?
Also, could you provide an example of this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Backreferences and backtracking are two different things. The former is using the results of a capture later in code, e.g.
This will match a single- or double-quoted string (ignoring escapes for the moment). It uses a backreference to refer to the open symbol (the single or double quote) so it can match that at the end.
Backtracking, on the other hand, is what regular expressions do naturally during the course of matching when a match fails. For example, if I’m matching the expression
against the string
then it will first match
aaaaaabcon the.+and comparebagainst the remainingd. This fails, so it backtracks a bit and matchesaaaaaabfor the.+and then compares the finalbagainst thec. This fails too, so it backtracks again and triesaaaaaafor the.+and the matches thebagainst theband succeeds.