开发者

Lua pattern matching: problem specifying the pattern to match

I am attempting some pattern matching in Lua and have hit a s开发者_运维知识库mall 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?


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜