In regex, |
is used for alternation. What is the corresponding character in Lua patterns?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
First, note that Lua patterns are not regular expressions; they are their own simpler matching language (with different benefits and drawbacks).
Per the specification I've linked to above, and per this answer, there is no alternation operator in a Lua pattern. To get this functionality you'll need to use a more powerful Lua construct (like LPEG or a Lua Regex Library).
回答2:
Another workaround is: Instead of:
apple|orange
Write:
[ao][pr][pa][ln][eg]
Explanation: match alternate letters from each word. voila!