so let's say I have a main function with some arbitrary code:
void main(){
//Some random code
int a = 5;
int b = a + 7;
}
and the text of this function is stored inside an std::string:
std::string mystring("void main(){ //Some random code int a = 5; int b = a + 7;}");
I want to use std::regex in order to extract out the body of the function. So the result I would be getting back is:
"//Some random code int a= 5; int b = a + 7;"
My issue is I do not know how to format the regular expression to get what I want. Here is my code I have right now:
std::string text("void main(){ //Some random code int a = 5; int b = a + 7;}");
std::regex expr ("void main()\\{(.*?)\\}");
std::smatch matches;
if (std::regex_match(text, matches, expr)) {
for (int i = 1; i < matches.size(); i++) {
std::string match (matches[i].first, matches[i].second);
std::cout << "matches[" << i << "] = " << match << std::endl;
}
}
My regex is completely off and returns no matches. What do I need to make my regex in order for this to work?