Regular expressions can be non-optimal like the following:

/yes or no|yes and no/

The above can be simplified to:

/yes (?:or|and) no/

Does anybody know of software to optimize regular expressions?

  • First of all, define "optimize". Do you want them to be faster? Shorter? More readable?
    – Alejandro
    Nov 8, 2021 at 22:57
  • ^ This is a valid question. A regex can be made shorter but at the expense of readability. It will not necessarily run faster by virtue of being shorter. So "optimize" could mean very different things. In that example a regex is not even needed. All you need is to check that the string matches an item in a list. In the past I have used software like Expresso because it is bundled with a library of common expressions (easier for noobs). It's often easier to start with an existing, proven pattern and adjust it to your needs.
    – Kate
    Nov 8, 2021 at 23:07
  • @Alejandro I am interested in run-time efficiency: execution time and memory usage.
    – ceving
    Nov 9, 2021 at 8:16
  • Don't know of any automated tools, but I personally use one of these visualizers when working on complex expressions: [regexr.com] or [regex101.com]
    – Lockszmith
    Nov 11, 2021 at 5:48

1 Answer 1


I'm quoting this answer by @gpojd on Stack Overflow:

If you are using perl, you could use Regexp::Optimizer or Regexp::Assemble.

I don't know of any online tools that do what you ask.

I have no experience with those tools (or any other that would be capable of this).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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