I try to parse the content of the file with a regex:
ifstream file_stream("commented.cpp",ifstream::binary);
std::string txt((std::istreambuf_iterator<char>(file_stream)),
std::istreambuf_iterator<char>());
cmatch m;
bool result = regex_search(txt.c_str(), m, regex("^#(\S*)$",regex_constants::basic));
The file is a c source, and it begins with the line:
#include <stdio.h>
I'm trying to parse a directive, i checked the regexp in regexbuddy and it works 100%, but in std::regex regex_search
returns false. It seems that $
character is not gettinc recognized and also ^
for the posix
syntax. I have tried to use ECMAScript
, and the regex works, only if i remove $
symbol.
//ecmascript syntax
bool result = regex_search(txt.c_str(), m, regex("^#(\S*)"));
The file is read using binary flag, so the txt
string, keeps all \r\n
characters which are required for $
syntax. I look for help, how to resolve this issue.