Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我的句子: 你好,世界。我是一只狗。
我正在使用搜索框,我想复制 Google 的自动完成功能。当用户输入单词时,匹配的字符被选择。我想匹配包含所有单词的所有句子,无论顺序如何。所以例如..
这些关键字将匹配“Hello world。我是一条狗”。
hello dog hello dog i dog world hello world dog am
如果我正确理解您的问题,您可以使用前瞻断言。
“你好狗”的一个例子:
^(?=.*dog)(?=.*hello).*$
对于“我狗世界你好”:
^(?=.*i)(?=.*dog)(?=.*world)(?=.*hello).*$
等等。
您不需要为此使用正则表达式。实际上,我不明白您如何为此使用正则表达式。
标记该行explode(" ", $line);,然后查看是否所有单词都匹配。
explode(" ", $line);