3 ms·
Another very-cool undocumented feature on another regex engine is re2's Set. It compiles a collection of regex to a single regex, and so allows you to very eff
by willvarfar 11y ago
Another very-cool undocumented feature on another regex engine is re2's Set. It compiles a collection of regex to a single regex, and so allows you to very efficiently match a string against an array of patterns.
- andreasvc 11y agoWhich re2? I maintain a fork of re2 but it's not in there [1]. If you mention re2 the main cool feature about it is that it is efficient, matching in linear time using DFA. Unfortunately unicode strings need to be encoded to utf8 but if you can design your application to work with utf8 bytestrings you can avoid that cost. [1] http://github.com/andreasvc/pyre2 http://github.com/andreasvc/pyre2
- willvarfar 11y agohttps://github.com/google/re2/blob/master/re2/set.h https://github.com/google/re2/blob/master/re2/set.h <-- c++ API https://github.com/google/re2/blob/master/re2/prog.h#L339 https://github.com/google/re2/blob/master/re2/prog.h#L339 <-- c
- andreasvc 11y agoNeat. I should consider wrapping that.
- fanf2 11y agoAnother package that does this is re2c [1] which is used by spamassassin to compile its rulesets to scan messages faster. [1] http://re2c.org http://re2c.org