Skip to content

recommend against std::regex #2328

Description

@jklowden

SL.regex: Regex merely says,

is the standard C++ regular expression library. It supports a variety of regular expression pattern conventions.

It does not say what is IIUC true:

  • specification and QoI conspire to make it too slow for any use where performance matters
  • "present guidance" from the committee is to use something else

In GCC COBOL a single file, lexio.cc, relies on regex to apply text substitution to COBOL inputs. It was written using std::regex with extended POSIX regular expression grammar. (The compiler uses GNU Flex and does not accept UTF-16 or UTF-32 inputs.) Early testing showed the module failed to terminate in minutes on files of a few hundred lines.

Rather than abandon the interface, I re-implemented a subset of std::regex as dts::regex using regex(3) in the naïve hope that one day a better implementation would come along. If it did, though, it would contradict the feedback for P1844R0:

std::regex performance is very poor relative to other available solutions. We don't want to spend resources enhancing std::regex when our present guidance is to use something else if at all possible.

I do not know what our venerable authors' opinion of std::regex is. From what I see, the guidelines as they now stand for it do not meet the criteria expressed in the introduction,

Consider these rules ideals for new code, opportunities to exploit when working on older code, and try to approximate these ideals as closely as feasible.

because there is ample evidence std::regex has problems, and no evidence anyone has a solution to them.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions