samedi 24 février 2018

Match function definition using regex

I want to match a function definition. Function definition can be like

int foo () {
    // Some statement
}
int foo(int a, int b){}
int foo ()
{
}

I have written a regex foo\s*\([\w, ]*\)\s*{ and tried it in atom text editor and it is running fine. But when I try to run it in C++14 complier it gives me regex_error(). My C++ regex is regex b("foo\s*\([\w, ]*\)\s*{");. I have also tried double escaping the brackets as \\( but still it's not working.

Aucun commentaire:

Enregistrer un commentaire