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.

  • Why not use a regex library and the notation that goes with it? Aug 20, 2016 at 11:02
  • Because of bloat. My regex is constant. Aug 20, 2016 at 12:05
  • Well, you can probably convert it to BNF and then create a parser out of it. Not sure if that's worth getting rid of the "bloat" though. And we'll laugh our arses off if that single regex expands to multiple regex. Aug 20, 2016 at 17:18
  • It just needs to expand to code hehe :) My binary exploded 5x after using <regex>, generated code can easily beat that, I believe Aug 20, 2016 at 19:13
  • 1
    nothing automatic but you can do this with gpt4 and lots lots lots of handholding
    – Rainb
    May 24, 2023 at 12:28

2 Answers 2


A few suggestions shamelessly copied from a similar SO question:

  1. 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.

  1. regextl - dumps the state machine for a regular expression.

I haven't tried any of these so I can't actually recommend anything.

  • 1
    1. is a lexer, which I don't need, 2. is unfinished. I'll just make my own if this keeps up. Aug 21, 2016 at 11:08
  • 1
    Note that the fact that (1.) is a lexer does not mean it doesn't have the functionality you need. It might be using regexp matching for lexing. Anyway, if you do decide to write your own, please post an answer here with the link, I wouldn't mind having that.
    – einpoklum
    Aug 21, 2016 at 11:13

Fo rmany years I have been extremely happy wiht RegEx Buddy. It is not free, but reasonably priced (and the OP does not ask for free).

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.

Rely on RegexBuddy to handle the details, such as which classes and function calls to use, and how to escape special characters. Just select the language you are working with, and the action you want to perform. Test whether a string matches a regex, extract matches from a string, search and replace, split a string, etc. RegexBuddy knows all the common regex actions and how to perform them with a variety of programming languages: C#, VB.NET, VB 6, Delphi, Java, Perl, PHP, JavaScript, VBScript, Python, Ruby and C/C++.

Read more about RegexBuddy's support for various programming languages Watch a video showing how to develop software with regular expressions

enter image description here

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.

Learn how you can avoid risk by testing and debugging regexes

Watch a video showing how to test and debug regular expressions enter image description here

  • I don't see any code, make some C/C++ code and post it here please. Oct 20, 2016 at 11:16
  • The code is in the first image. Why not download the trial and generate some C/C++ yourself?
    – Mawg
    Oct 20, 2016 at 11:54
  • 1
    There's no code implementing a DFA there. Oct 20, 2016 at 11:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.