简体   繁体   中英

How to get a particular word/string in lua regex

I have a problem to get a string. Here is my code:

conf = "option fn_o 'Operator'"
print(conf)
local s, e, pa = string.find(conf, "\b(?!option|fn_o)\b\w+")
print(s, e, pa)

I want to get an Operator only. In Javascript, that regex works good, but in Lua it doesn't. I think there is no problem because Lua is based on json so it is similar to javascript. Is there any problem?

Lua does not support full regular expressions out of the box, but there are libraries that do.

Lua includes patterns , which suffice for your task.

This code gets the string inside single quotes:

print(string.match(conf, "'(.-)'"))

The pattern reads: find a single quote and capture everything until the next single quote.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM