I need a code generator that transforms a regular expression in any notation into C or C++ code, that allows recognition and extraction of data from the input.
A few suggestions shamelessly copied from a similar SO question:
- re2c - "regular expression to C" says it's about generating lexers:
re2c is a lexer generator for C/C++. Its key features are:
Very fast lexers: the generated code is as good as a carefully tuned hand-crafted C/C++ lexer. It’s because re2c generates minimalistic hard-coded state machine (as opposed to full-featured table-based lexers).
but might still do what you want, if it actually takes regexps anywhere.
- regextl - dumps the state machine for a regular expression.
I haven't tried any of these so I can't actually recommend anything.
Develop Efficient Software Quickly with Instant Code Snippets
Save time and code efficiently by using regular expressions when developing applications and scripts. With the proper regex, you can often do in a single line of code, or a few lines of code, what would otherwise require dozens or hundreds.
Plus many more features. My favo(u)rite being
Regex Tester and Debugger
Don't risk actual data with untested regexes. Copy and paste sample data into RegexBuddy, or open test files. Step through the search matches in the sample data, and get a detailed report about each match. Or highlight all matches to debug the regex in real time as you edit it.
If a regex doesn't do what you want, debug it by looking at the complete matching process, eliminating all guesswork.