Regexp
Regexp copied to clipboard
[QUESTION] Escaping circumflex possible?
I wondered how to escape the circumflex char ^
My input is SETD^i.11.mix^0.1015118791
and i want to capture 11
and 0.1015118791
when i replace the circumflex with \094
the callback seems to run endlessly
@nickgammon Do you have an idea how to write the regex?
char buf [100] = "SETD^i.11.mix^0.1015118791";
MatchState ms (buf);
count = ms.GlobalMatch ("^i.(%d+).mix^([%d.]+)", match_callback); // no match
count = ms.GlobalMatch ("^i.(%d+).mix", match_callback); // no match
count = ms.GlobalMatch ("\^i.(%d+).mix", match_callback); // no match
count = ms.GlobalMatch ("\\^i.(%d+).mix", match_callback); // no match
count = ms.GlobalMatch ("\094i.(%d+).mix", match_callback); // endless loop in callback
if anyone is still interested: "%^i%.(%d+).*%^([%d.]+)" should work "(%d+)%D*([%d.]+)" would be easier but does not answer the question
@hatjan Thanks! I must have missed that one. @othmar52 You can always "escape" the circumflex with %. Un-escaped it is treated as "start of expression". Escaping in Lua patterns is done with % and not \ because \ is used inside strings (eg. \n), and it would be a pain to use double \\ everywhere.