4

Earlier I posted a question about regex which resulted in stackoverflow error in java. My Regex was greedy and many commented to use possessive quantifier in regex. So, I started learning Possessive quantifier in regex.

I tried to match string between double quotes. My regex is

"([^\\"]|\\.)++"

I tried to match the string

"Hello I am \" chitti"

While matching there was backtracks. I tested using http://regex101.com/#PCRE. The link to regex is REGEX 101 LINK

enter image description here

Can someone please explain why there is a backtrack involved steps 6,8,10 etc

Jerry
  • 70,495
  • 13
  • 100
  • 144
Krishna M
  • 1,135
  • 2
  • 16
  • 32

1 Answers1

3

There shouldn't be a backtrack there. I would expect (and RegexBuddy shows) backtracks at the \" and at the final ", but not in these positions.

RegexBuddy screenshot

Perhaps regex101.com displays a BACKTRACK message also when the regex engine explicitly discards a potential backtracking position, but that's only speculation on my part.

Tim Pietzcker
  • 328,213
  • 58
  • 503
  • 561