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
You can just concatenate the regexes using or (|
) (and anchors for the beginning/end of string).
Most good regex libraries optimize their finite state automata after they build it from your regex. PCRE does that, for instance.
This step usually takes care of your optimization problem, ie. they apply most of the transformations you would have to do "by hand".