I try to use multiline regex syntax, so that ^$
match beginning and end of line in C++. Since C++17, std::regex
and std::regex_constants
should contain a flag multiline
that turns this on (see the reference).
I've tried this on Apple Clang, GCC on Ubuntu and Alpine. In none of those it works, the symbol is said to be missing. What am I doing wrong? Did I misunderstand this is in the standard since C++17?
#include <regex>
int main() {
auto flag = std::regex::multiline;
}
$ g++ --version
g++ (Ubuntu 9.2.1-9ubuntu2) 9.2.1 20191008
$ g++ regex.cpp -std=c++17 -o regex
regex.cpp: In function 'int main()':
regex.cpp:3:27: error: 'multiline' is not a member of 'std::__cxx11::regex' {aka 'std::__cxx11::basic_regex<char>'}
3 | auto flag = std::regex::multiline;
| ^~~~~~~~~
About 2.5 years later, std::regex::multiline
is indeed present in GCC12 and up and Clang 15 and up: https://godbolt.org/z/bocnr9Yab