Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Save/Serialize boost or std regexes

Tags:

c++

regex

std

boost

Is it possible to serialize/deserialize and save/load regular expressions to/from a file?

We have a very time consuming process that constructs some regexes and I'm wondering if we can save some time by saving and loading them.

like image 971
MBZ Avatar asked Sep 11 '13 23:09

MBZ


1 Answers

No, it is probably not possible because it would require you to recompile the regex anyway.

However, if you use boost::xpressive, you can do the compilation of the regex during compile time via expression template construction of the regex. This will make it make the regex compile time go away entirely.

Boost Xpressive

However, the true cause of your excess time usage is almost certainly that you are using regexes improperly, IE, through the use of a backtracking regex engine.

RE2 is a traditional automata regex engine that does not use backtracking, but instead constructs an NFA or DFA directly. If you are not using backreferences or many non-regular expression based "features", using RE2 will show an order of magnitude increase in speed for many corner cases.

If you are using those features, you should be aware that they will strictly dominate the speed of your matching, and they are almost certainly the primary cause of the slow down you seek to eliminate.

like image 85
Alice Avatar answered Sep 30 '22 14:09

Alice