#include <iostream>
Can anybody please help me to extract till "/" or "0x2f" into b(string) ??
Please do the needful.
#include <pcrecpp.h>
using namespace std;
int main() {
string str1("hello0x3Ftest/test/etsdf");
pcrecpp::RE re("([^(/|?:0x2F)].*)/(.*)/(.*)");
string b, k, p;
if ((re.FullMatch(str1, &b, &k, &p)) ) {
cout<< "\n b: "<<b << " k: " << k <<" P: "<<p<<endl;
} else {
cout<<"invalid\n";
}
}
output : b: hello3Ftest k: test P: etsdf
but Expected output :
output : b: hello
.* is greedy, try .*? to get the shortest match rather than the longest
Last edited on
What exactly do you want the expression to do?
I don't know the regex engine you are using but you might want to try this, it may do what you want: "([^/]+)(?:/|$)"
It says take everything that is not a '/' until you meet a '/' or the end.
Last edited on
I want to extract until "/" or "0x2F" ..I meant to say that if I encode "/" to hex then also I want to extract until "/".
Regular expressions are overkill for this. Just search the input string for "/" and "0x2F" and cut the string at whichever comes first.