Regexp icon indicating copy to clipboard operation
Regexp copied to clipboard

[QUESTION] Escaping circumflex possible?

Open othmar52 opened this issue 4 years ago • 2 comments

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

othmar52 avatar Jun 26 '20 17:06 othmar52

if anyone is still interested: "%^i%.(%d+).*%^([%d.]+)" should work "(%d+)%D*([%d.]+)" would be easier but does not answer the question

hatjan avatar Jul 30 '24 12:07 hatjan

@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.

nickgammon avatar Jul 31 '24 22:07 nickgammon