Boost :: xpressive to see the beginning of the sequence

I am using boost :: xpressive to parse in a text file. I want to see only if the line starts with the character '#' (once).

I am using the following code

std::string str1 = "## this could be my line";
sregex rex1 = sregex::compile("^#+");
smatch result1;
if(regex_match(str1,result1,rex1){
    std::cout << result1[0] << '\n';
}else{
std::cout << "match not found!\n";
}

But I always get “match not found!” Even when the lines begin with C #. Can anyone help me here?

By the way, can someone help me write a rex1 instruction using boost :: xpressive 'bos'?

Thank! Aisha

+3
source share
1 answer

Use regex_searchinstead regex_match.

And here is the static xpressive syntax for rex1:

bos >> +as_xpr('#');
+3
source

All Articles