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

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -