本文介绍了如何匹配正则表达式中的多个单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
只是一个简单的正则表达式我不知道如何写。
Just a simple regex I don't know how to write.
正则表达式必须确保字符串匹配所有3个单词。我知道如何使它匹配任何 3:
The regex has to make sure a string matches all 3 words. I see how to make it match any of the 3:
/advancedbrain|com_ixxocart|p\=completed/
但我需要确保所有 3字字符串中存在。
but I need to make sure that all 3 words are present in the string.
以下是单词
- advancebrain
- com_ixxocart
- p =已完成
推荐答案
使用:
^(?=.*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)
这篇关于如何匹配正则表达式中的多个单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!