Using regular expression to extract multiple values and escaping characters in regex

Hi all,

I’m having some difficulties using the Poco::RegularExpression library. What i try to do is filter out multiple values from a string that is in a logfile format. This is an example of a string i’m trying to dissect:

05:53:42.576005 2889891532us tsft 1.0 Mb/s 2412 MHz 11g -69dB signal antenna 1 BSSID:Broadcast DA:Broadcast SA:00:00:00:00:00:00 (oui Unknown) Probe Request (wirelessSSID) [1.0* 2.0* 5.5* 6.0 9.0 11.0* 12.0 18.0 Mbit][|802.11]

The parts in bold are the parts that i’m interested in, the string is a probe request i’ve filtered out with tcpdump. the first bold/italic part is the timestamp (i don’t know what type of timestamp this is, if you recognize it please enlighten me!) The second bold part is the Signal strength, the third part is the mac address, and the last part is the probed SSID.

I’ve created an RegEx with an online regex tester, the regex i created is the following:

"(.*? .*?) (.*?) (.*? .*?) (.*? .*?) (.*?) (.*?) (.*?) (.*? .*?) (BSSID:.*?) (DA:.*?) (SA:.*?) (.*? .*?) (.*? .*?) \((.*?)\) \[(.*?)\]"

But when i try to use this with the Poco::RegularExpression lib i get an error with the formatting of my regex.

RegularExpression regEx("regex as described above")
std::vector<std::string> data;
regEx.split(message, 0, data); // crashes on this line

The error i get is:
libc++abi.dylib: terminating with uncaught exception of type Poco::RegularExpressionException: Error in regular expression

I tried removing the backslashes \ from the regex and the parts the backslash has to escape ( e.g \((.*?)\) becomes (.*?) ), after removing those parts the regex works but i have the feeling it will not be as stable as i want, for example the SSID is enclosed in () and i find it by using \((.*?)\) as the regex by including the escaped () the regex is prepared for SSIDs that have whitespace in them.

I can imagine that the regular expression i made is not the most efficient one, but i’m no expert at creating regexes :wink:
If some of you guys and girls have any feedback on dissecting the line i want to dissect or have some good tutorials on using regexes in c++ please let me know! I would really appriciate the help!

Many Thanks,

Long time ago, but still having the same issue:

escaping square brackets like this "\]" results in no matches,
and if used in a lookbehind/lookahead like this "(?<=\[)hello(?=\])" it gives me an exception:

Got Exception Error in regular expression: missing ) (at offset 19) 0

where can I find a good documentation about poco::regularexpression?

thanks in advance!

okay… in my case having two backslashes seems to solve the problem, maybe because you have to escape the program itself first and then the search pattern?

"(?<=\\[)hello(?=\\])" is finding “hello” in the string "[hello]" :heavy_check_mark: