Lua string.match uses irregular regular expressions?

Lua doesn't use regex. Lua uses Patterns, which look similar but match different input.

.* will also consume the last ? of the input, so it fails on \\?. The question mark should be excluded. Special characters are escaped with %.

"how[^?]*%?"

As Omri Barel said, there's no alternation operator. You probably need to use multiple patterns, one for each alternative word at the beginning of the sentence. Or you could use a library that supports regex like expressions.


According to the manual, patterns don't support alternation.

So while "how.*" works, "(how|what).*" doesnt.

And kapep is right about the question mark being swallowed by the .*.

There's a related question: Lua pattern matching vs. regular expressions.

Tags:

Regex

Lua