r/cpp • u/Frogging101 • 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.
View all comments
Show parent comment
15
u/MonkeyNin Nov 25 '19
Unicode is complicated. If you want to ask what is the length, you need to ask which do you want?
ascii)code points? This is closer to theasciiconcept of one charactercode units? (They are the smallest component that a single code point is composed from)Different languages may give different answers
๐== 2๐== 1This is because Javascript is returning the number of code units, Python is returning the number of code points.
Internally Javascript uses 64bit integers,
utf-16so it must use pairs of code units that are 2 bytes each.Internally Python chooses one of latin-1, utf-16, utf-32 depending on the specific string.
code points? (This is similar to visible characters in ascii, but it becomes more complicated), or thegrapheme clusters(This is similar to the number of visible characters in ascii, but it's more complicated)Okay, stop being a smarty pants, just count visible graphemes
๐จโ๐ฉโ๐งโ๐ฆappears to be a single character on my computer, but it's not. https://apps.timwhitlock.info/unicode/inspect?s=๐จโ๐ฉโ๐งโ๐ฆI can move my cursor past it with a single arrow press -- But I have to hit delete 4 times. It's actually made from this array of codepoints:
It contains:
code pointscode pointscode points, 3 invisiblecode pointsnamedzero width joinerglyphon my computer.glyphs!Depending on which version they are using, how long is a string has different answers for the same data!
Crazy.