[Solved] C++ regular expression

Given that you know the probe part ends with } and the IP part end with a &, it’s probably easiest to just scan for those:

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

One minor detail: scanf with either a scanset or a %s conversion needs to have the buffer size specified to have any safety at all. without a length, both are pretty much equivalent to gets for lack of safety, so you really want something like:

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

Also note that this will give you the probe part without the trailing }. If you really need it, you can use something like strncat to add it back on afterwards though.

For those looking on: no, scanf (and company) don’t support full regular expressions, but they do support scansets, which is what he’s using here.


solved C++ regular expression