有没有包含长尾词的句子,string.find能找到吗?

2026-04-01 20:431阅读0评论SEO基础
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计198个文字,预计阅读时间需要1分钟。

有没有包含长尾词的句子,string.find能找到吗?

我使用了一个函数来查找字符串,但看起来代码非常简陋。+function+find_without_pattern(s1, s2)+for+i+=1+,+…+

我应用了一个函数,但看起来很糟糕.

function find_without_pattern(s1,s2) for i =1,#s1-#s2+1 do local t = string.sub(s1,i,#s2+i-1) if t == s2 then return i,i+#s2-1 end end end string.find方法提供了一个可选的第4个参数来自行强制执行 plaintext search.

例如:

有没有包含长尾词的句子,string.find能找到吗?

string.find("he#.*o", "e#.*o", 1, true)

会给你正确的结果.

引用Lua手册页:

string.find (s, pattern [, init [, plain]])

A value of true as a fourth, optional argument plain turns off the pattern matching facilities, so the function does a plain “find substring” operation, with no characters in pattern being considered magic. Note that if plain is given, then init must be given as well.

本文共计198个文字,预计阅读时间需要1分钟。

有没有包含长尾词的句子,string.find能找到吗?

我使用了一个函数来查找字符串,但看起来代码非常简陋。+function+find_without_pattern(s1, s2)+for+i+=1+,+…+

我应用了一个函数,但看起来很糟糕.

function find_without_pattern(s1,s2) for i =1,#s1-#s2+1 do local t = string.sub(s1,i,#s2+i-1) if t == s2 then return i,i+#s2-1 end end end string.find方法提供了一个可选的第4个参数来自行强制执行 plaintext search.

例如:

有没有包含长尾词的句子,string.find能找到吗?

string.find("he#.*o", "e#.*o", 1, true)

会给你正确的结果.

引用Lua手册页:

string.find (s, pattern [, init [, plain]])

A value of true as a fourth, optional argument plain turns off the pattern matching facilities, so the function does a plain “find substring” operation, with no characters in pattern being considered magic. Note that if plain is given, then init must be given as well.