I would like to grab everything before ] in aasd{123;'asd'aaaa]asd. So I tried to create regex but regex.h works weird.
Closest I get: ".*[^\\]]" which gives me: aasd{123;'asd'aaaa]
#include <regex.h>
#include <iostream>
#include <cstring>
using namespace std;
int main(){
const char* phrase = "aasd{123;'asd'aaaa]asd";
const char* expression = "........"; // <- what should be here?
size_t group_size = 5;
regmatch_t *pmatch = new regmatch_t[group_size];
memset(pmatch, 0, sizeof(regmatch_t) * group_size);
regex_t regex;
int reti = regcomp(®ex, expression, REG_EXTENDED);
if (reti){
cout << "Error1" << reti <<endl;
return false;
}
reti = regexec(®ex, phrase, group_size, pmatch, 0);
if (reti){
cout << "Error2 " << reti <<endl;
return false;
}
int len = 0, i = 0;
char result[10000];
for (i = 0; pmatch[i].rm_so != -1; i++){
len = pmatch[i].rm_eo - pmatch[i].rm_so;
memcpy(&result, phrase + pmatch[i].rm_so, len);
cout << "num " << i << " " << result << endl;
}
}