Reputation: 173
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
Upvotes: 3
Views: 239
Reputation: 62975
Use regex_search
instead of regex_match
.
And here is the static xpressive syntax for rex1
:
bos >> +as_xpr('#');
Upvotes: 3