Regular Expression Engineering

What can regular expressions, viewed through a software-engineering microscope, teach us about building software?

A software-engineering microscope
A regular expression, described as one line of software, sits at the centre of three radial spokes with no enclosing triangle. The spokes are three perspectives on the same artifact: regex theory asks what it should mean, through semantics, language features and expressiveness; human factors asks how people reason about it, through comprehension, decision-making, reuse and repair; regex engines ask what happens when it runs, through matching algorithms, performance, ReDoS and defenses. The research results sit in the open sectors between the spokes. Between theory and human factors, portability and composition asks whether meaning survives movement and reuse. Between theory and engines, realization asks whether the engine realizes the intended semantics safely. Between human factors and engines, security in practice asks whether developers can recognize and control pathological behavior.

Regular expressions are a niche topic, and that is part of why they are useful to study. A regex may be only one line of code, yet it is an unusually compact meeting point between formal semantics, human programming behavior, and the implementation choices of the engine that executes it. Many of the problems of software engineering become visible here at a scale where we can study them closely.

That perspective is personal as well as methodological. At IBM, I maintained hundreds of regular expressions used to parse the unstable and largely unspecified output of dozens of command-line tools and their many operating modes. Small expressions became critical infrastructure: reused constantly, difficult to reason about, and dependent on assumptions scattered across languages, runtimes, and evolving interfaces.

We study regular expressions as software artifacts. Across this program, we have asked what their formal semantics promise, how developers understand and reuse them, and how matching engines realize them in practice. Bringing those perspectives together exposes gaps that are easy to miss when any one layer is studied alone.

A small artifact can become critical infrastructure

The programme began with a runtime failure: a single expensive input could stall an entire event-driven server, because one regular expression sat on the path every request took. That framing — performance as a security property — set up everything that followed, and measuring the ecosystem rather than the example turned a known theoretical hazard into a demonstrated and widespread one.

Shared syntax does not guarantee shared meaning

Regular expression syntax looks portable, and developers reuse it as though it were. It is not. Dialects disagree about what an expression matches, behaviour learned in one language does not transfer intact to another, and composing expressions introduces assumptions that neither part carried alone.

Compact notation does not make reasoning easy

If a one-line artifact is hard to reason about, that is a software-engineering finding rather than a user error. We study what developers actually understand about the expressions they write and reuse, and what an analysis tool has to explain before its findings can be acted on.

Execution is part of the semantics that matter

What an expression means in practice includes what the engine does to produce that meaning. Backtracking implementations turn ordinary expressions into pathological ones on some inputs, so the questions of which semantics to preserve, and at what cost, belong to engine design — not solely to the programmer writing the expression.

Security failures cross the layers

ReDoS is not a defect in any single layer. It appears when a formal property, a developer’s expectation, and an implementation’s cost model disagree, so a defense has to hold at whichever layer is reachable. Sanitization intended to make input safe can itself introduce the vulnerability — and the ecosystem study, the anti-pattern work, and the backreference results above each show, from a different direction, that addressing one view alone leaves the others open.

  • Exploiting Input Sanitization for Regex Denial of Service
    ICSE · 2022
    Published sanitization logic tells an attacker which inputs reach the matcher, turning a usability feature into an exploitation aid.
  • On the Impact and Defeat of Regex DoS
    The Student Research Competition statement of the ReDoS problem and its defences.

What the regex microscope revealed

Across these studies, the recurring lesson is that even very small software artifacts cross boundaries between specification, human understanding, and implementation. Reuse carries assumptions across those boundaries; failures appear when the assumptions do not travel with the artifact.

Funding and support

This work has been supported by: