regex - Java Runaway Regular Expression: Catastrophic Backtracking -
can explain me why regular expression:
[a-za-z]+\s(.+?)+\s(?:pr.|g.|a.)|[a-z][a-za-z]+\.\s[a-za-z+\s(?:pr.|g.|a.)|[a-za-z]+\s(?:pr.|g.|a.)|[a-za-z]+\s[a-za-z]+\s(?:pr.|g.|a.)
with input:
testės r. sav., Žtestčių vhest sen., platakių k.
is causing catastrophic backtracking?
on other hand, if add ^ , $, like:
^[a-za-z]+\s(.+?)+\s(?:pr.|g.|a.)|[a-z][a-za-z]+\.\s[a-za-z+\s(?:pr.|g.|a.)|[a-za-z]+\s(?:pr.|g.|a.)|[a-za-z]+\s[a-za-z]+\s(?:pr.|g.|a.)$
there no backtracking.
(tested regex101.com)
however, when try use regular expression (^$ included) java:
matcher matcher = myregexpattern.matcher(string); if(matcher.find()){ // }
backtrack persists... ideas how avoid backtrack using java?
Comments
Post a Comment