I am trying to search and split a string based on regex. Suppose I have a string named var which looks like
| | | |-DeclRefExpr 0x5d91218 <col:5> 'int' lvalue Var 0x5d91120 'y' 'int'
Now I would like to split this into
| | | |-DeclRefExpr 0x5d91218 <col:5>
int
lvalue Var 0x5d91120
y
int
I know that the regex will be something like [^']* but I cant figure out how I can do it. What I have tried so far is:
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <regex>
using namespace std;
int main(){
std::string var = " | | | |-DeclRefExpr 0x5d91218 <col:5> 'int' lvalue Var 0x5d91120 'y' 'int'";
std::regex rgx("[^']*");
std::smatch match;
if (std::regex_search(var.begin(), var.end(), match, rgx)){
cout << match[3] << endl;
}
return 0;
}
[^']*'[^']*'[^']*'[^']*'[^']*'[^']*', plus capture groups in the appropriate places?