c# - Regex extremely slow when close matching -
i attempting fix regex searches html elements attributes named "langtoken" other permutations such "langtoken_title". if search langtoken using word boundary returns results ~1,750,000 character string in around 0.2 seconds if omit word boundary capture langtoken_title attributes spikes around 95 seconds.
the regex had was
<([^>\s]+) [^>]*langtoken([^>]*?(\\*)?/>|.*?<(\\*)?/\1>)
so far attempts have changed to
<([^>\s]+) [^>]*langtoken(?:\b|_)(?:[^>]*/>|.*?</\1>)
i should note in string being searched (an html document) there 1431 occurrences of elements langtoken attribute , 5 of langtoken_title attribute. believe near match causing issue not sure.
this first foray regex , appreciated in creating more efficient expression.
Comments
Post a Comment