Merge several regexes to a single one
问题 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 these regexes as a single regex. For example, if a have these regexes: 'foo *bar' 'foo *zip' 'zap *bar' I would like to obtain something like 'foo *(bar|zip)|zap *bar'. Is there some algorithm, library or tool to do this? 回答1: You can just concatenate the regexes using or ( | ) (and anchors for the beginning/end of string).