java - Finding all regular expression/s from a value -


i have variable having url , file containing 100's of regular expression. how can find regular expression/s hold true variable. don't want pattern match each , every pattern in file. looking performance efficient solution.

while, ultimately, won't away "true" performance-efficient solution, there simple heuristics can utilize cut down on number of patterns need evaluate.

for instance, try "grouping" patterns using simplified versions. consider 2 patterns

[a-z]\d[a-z] [a-z]{3} 

any string matching both of these patterns match pattern [a-z].[a-z]. if skip previous 2 patterns if more general pattern doesn't match, you'll (likely) save on overall processing time. more can generalize, more patterns can eliminate @ once. ultimate expression of hierarchical, in patterns follow file-system-like organization of groups. while worst-case performance of system worse going through patterns, average case better different groups of patterns eliminated.

you're not going better o(n) performance on number of regexes, you're have savings on coefficient of n.


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -