且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何匹配正则表达式中的多个单词

更新时间:2022-03-28 23:05:45

使用前瞻性断言

^(?=.*advancebrain)(?=.*com_ixxochart)(?=.*p=completed)

如果所有三个条款都存在,

将匹配。

will match if all three terms are present.

您可能想要添加 \b 围绕搜索字词的工作边界,以确保它们匹配为完整的字词,而不是其他字词的子字符串(例如 advancebraindeath )如果你需要避免这种情况:

You might want to add \b work boundaries around your search terms to ensure that they are matched as complete words and not substrings of other words (like advancebraindeath) if you need to avoid this:

^(?=.*\badvancebrain\b)(?=.*\bcom_ixxochart\b)(?=.*\bp=completed\b)