【发布时间】:2016-09-04 03:27:38
【问题描述】:
这已经在Pattern in lua with anchors not matching 被问过,但是我有一个测试用例表明它似乎仍然不起作用:
patterns = {
'a@b',
'^a@b',
'a@b.com',
'my-a@b',
'my-a@b.com',
'a@b.com$',
'^this-is-my-a@b.com',
'this-is-my-a@b.com$',
'^this-is-my-a@b.com$',
}
test = "this-is-my-a@b.com"
for _, pattern in ipairs(patterns) do
print(pattern .. ": " .. test .. "\n\tfind: " .. (test:find(pattern) or 'nil') .. "\n\tmatch: " .. (test:match(pattern) or 'nil'))
print(pattern .. ": " .. test .. "\n\tfind: " .. (string.find(test, pattern) or 'nil') .. "\n\tmatch: " .. (string.match(test, pattern) or 'nil'))
end
我做了单独的 test:find 与 string.find(test...) 只是为了确保没有恶作剧。
有人能告诉我如何让我的锚定模式发挥作用吗?
【问题讨论】:
-
lua版本是5.1.4
-
.和-是正则表达式上下文中的特殊字符。所以你需要逃避它们。
标签: lua anchor string-matching