Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lua pattern matching: problem specifying the pattern to match

I am attempting some pattern matching in Lua and have hit a small problem. I am trying to match everything from the first newline character in my data up to the following pattern _\x0C.

here is the code that has the problem:

configmatch = string.match(response, "\n(.+)(['_\x0C'])")

it seems to be working some of the time, other times it is "cutting short" the expected output. the problem is probably to do with this: (['_\x0C']) but i have been unable to resolve it. Does anyone know how to fix this?

like image 538
greatodensraven Avatar asked Dec 09 '25 03:12

greatodensraven


1 Answers

If you want _\x0C literally in the string, you need to use "\n(.-_\\x0C)". If you mean underscore followed by formfeed, use "\n(.-_\012)", because there are no \x escapes in Lua (5.1).

like image 81
lhf Avatar answered Dec 10 '25 17:12

lhf