4 ms·
There is a library (I think it is Google's re2) that supports throwing a bunch of regular expressions into a single structure, matching an input string against
by koenigdavidmj 12y ago
There is a library (I think it is Google's re2) that supports throwing a bunch of regular expressions into a single structure, matching an input string against all of them at once, and answering which patterns matched the input string. This gets you route lookup in time linear to the input string (or if not linear, still better than checking all the patterns one after another).
- f2f 12y agore2 is described here: http://swtch.com/~rsc/regexp/regexp3.html http://swtch.com/~rsc/regexp/regexp3.html
- rudolf0 12y agoI use RE2 and currently achieve this with regular string concatenation. Do you know if they provide an API for doing this without concatenation, and if it would be faster?
- koenigdavidmj 12y agoThe header file is available at https://code.google.com/p/re2/source/browse/re2/set.h https://code.google.com/p/re2/source/browse/re2/set.h , and if I recall correctly, it merges all the regexes into one DFA so that it's faster than just concatenating all your patterns into one string.
- deleted 12y ago[deleted]