regex - C++ regular expression -


i need capture data variable using regular expression. data available on form: ip=8.8.8.8&probe=ip/tcp{dst=53} example.

to achieve i`m using:

char *data; data = getenv("query_string"); char ipt[40]; char probe[40];  sscanf(data,"ip=%[0-9a-za-z-.]&probe=%[0-9a-za-z-.{}/=]",ipt,probe); 

the second field contain / can't , other special carachters ({}=)

what can do?

i tried:

sscanf(data,"ip=%[0-9a-za-z-.]&probe=%[(...)]",ipt,probe);  

and had no success well.

given know probe part ends } , ip part end &, it's easiest scan those:

sscanf(input, "ip=%[^&]&probe=%[^}]", ipt, probe); 

one minor detail: scanf either scanset or %s conversion needs have buffer size specified have safety @ all. without length, both pretty equivalent gets lack of safety, want like:

char ipt[256], probe[256]; sscanf(input, "ip=%255[^&]&probe=%255[^}]", ipt, probe); 

also note give probe part without trailing }. if need it, can use strncat add on afterwards though.

for looking on: no, scanf (and company) don't support full regular expressions, support scansets, he's using here.


Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -