r/cpp • • Nov 24 '19

What is wrong with std::regex?

I've seen numerous instances of community members stating that std::regex has bad performance and the implementations are antiquated, neglected, or otherwise of low quality.

What aspects of its performance are poor, and why is this the case? Is it just not receiving sufficient attention from standard library implementers? Or is there something about the way std::regex is specified in the standard that prevents it from being improved?

EDIT: The responses so far are pointing out shortcomings with the API (lack of Unicode support, hard to use), but they do not explain why the implementations of std::regexas specified are considered badly performing and low-quality. I am asking about the latter.

137 Upvotes

111 comments sorted by

View all comments

18

u/suthernfriend DevOps Engineer Nov 25 '19

Wasn't there a library from this Czech genius women which implements regexes with templates?

Edit : found it. Hana Dusikova https://youtu.be/QM3W36COnE4

6

u/alexej_harm Nov 30 '19 edited Nov 30 '19

It's actually quite slow with anything but the simplest patterns and doesn't support captures.

----------------------------------------------------------
Benchmark                Time             CPU   Iterations
----------------------------------------------------------
regex_std             3105 ns         3139 ns       224000
regex_re2              181 ns          180 ns      3733333
regex_hyperscan       96.2 ns         96.3 ns      7466667
regex_ctre             187 ns          184 ns      3733333
regex_spirit          44.5 ns         44.5 ns     15448276

https://gist.github.com/qis/3d9f5a73d9622847c8b7da68af7e19d4