boost::xpressive to see the beginning of sequence

248 Views Asked by At

I am using boost::xpressive to parse through my text file. I want to see if only when the line begins with a '#' (one of more times).

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 am always getting "match not found!", even when the lines begin with #. Can anyone help me here?

Incidently, can anyone also help me in writing the rex1 statement using the boost::xpressive 'bos'?

Thanks! Ayesha

1

There are 1 best solutions below

3
On BEST ANSWER

Use regex_search instead of regex_match.

And here is the static xpressive syntax for rex1:

bos >> +as_xpr('#');