How can I quickly try out a large number of regular expressions and find out which one matches?

I am writing a program in .net where the user can provide a large number of regular expressions. For a given string, I need to find out which regular expression matches this string (if there are several matches, I only need the first one that matches). However, if there are a large number of regular expressions, this operation can take a very long time.

I was somewhat hoping there would be something similar to flex (The Fast Lexical Analyzer (not Adobe Flex)) for .net, which would allow me to specify a large number of regular expressions still quickly (O (n) according to Wikipedia for n = len (line input)) find out which regular expression matches.

Also, I would prefer not to implement my own regex engine :).

+3
source share
3 answers

Find the largest piece of constant text in each regular expression (if above a certain threshold length) and use the Karp-Rabin algorithm to search for any of these lines at the same time. For each match, run this regular expression to see if all of this matches. For each regular expression that is not included in the multi-line search, search for that regular expression.

, , , .

+1

? , O (n) . ? Flex? , , .NET.

, List , , .

+1

- , lex, # Lex. .NET #, , , .

Java JLex JFlex, . , "off-line" ( ), . .NET, , .

0

Source: https://habr.com/ru/post/1746907/


All Articles