Merge several regexes to a single one

前端 未结 4 756
庸人自扰
庸人自扰 2021-01-12 14:15

I have several regexes (actually several thousands), and I must check if one string matches any of these regexes. It is not very efficient, so I would like to merge all thes

4条回答
  •  半阙折子戏
    2021-01-12 14:41

    In theory a regex is a (nondeterministic)finite-state automata; thus they can be merged and minimized. You can take a look at this as a starting point.

    Beware, though, that this might not be the most correct answer. Why do you have to deal with several thousands regular expressions? I can only fathom the maintentance hell of such a thing. Perhaps you should consider writing a parser and a grammar -- much easily done (and grammars are more powerful than regexps anyways).

提交回复
热议问题