I cannot get the right rule to work correctly. In multi-line text in ECMAScript, is this a regular expression begin\n([\s\S]*\nend)?
matches exactly what I need and I tested it here .
When I translated it into C ++, it does not correspond to the same text.
Here is my code in Visual C ++ 2010:
#include <iostream> #include <regex> int main(int argc, char *argv[]) { std::regex metadataBlockRegex("begin\\n([\\s\\S]*\\nend)?", std::regex::ECMAScript); std::string text = "begin\n" " 123\n" "end\n"; std::sregex_iterator blocksBegin(text.begin(), text.end(), metadataBlockRegex); std::sregex_iterator blocksEnd; for (auto blockMatch = blocksBegin; blockMatch != blocksEnd; ++blockMatch) { std::cout << (*blockMatch)[0].str(); } return 0; }
This only outputs the βbeginningβ, and I expected that it would fit the entire text.
My question is: what is wrong here, and where can I find a detailed description of the std::regex
engine syntax and how they handle multi-line strings.
source share