简体   繁体   English

Javascript Regex-单词必须与列表中的任何单词匹配,且顺序不限,且带有单词边界

[英]Javascript Regex - word must match with any word from list, in any order, with word boundary

I have the following regex: 我有以下正则表达式:

/^(?=.*?\bapple\b)(?=.*?\b(ipad|itunes)\b).*$/i

This matches the word "apple" and one word from the list eg "ipad" or "itunes" in any order. 这以任意顺序匹配单词“ apple”和列表中的一个单词,例如“ ipad”或“ itunes”。

I now need to extend this to have a word boundary eg apple can be no more than 10 words from any other in the list. 我现在需要扩展它以具有单词边界,例如,苹果列表中的其他单词不能超过10个单词。

I am using http://refiddle.com/ to build and validate. 我正在使用http://refiddle.com/进行构建和验证。

Can anyone advise. 任何人都可以建议。

这个长的正则表达式应该为您工作:

^(?=.*?((?:ipad|itunes)(?:\W+\w+){0,10}\W+apple\b|\bapple(?:\W+\w+){0,10}\W+(?:ipad|itunes)\b)).+$

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM