[英]Regular expression to match different versions of same word
I am trying to get a regular expression to match different versions of the same word. 我正在尝试获取正则表达式以匹配同一单词的不同版本。
for example: 例如:
If I have jQuery,jquery,JQUERY,Jquery
-> they should all be matched and total match count should be 4. I tried: 如果我有jQuery,jquery,JQUERY,Jquery
>它们都应该匹配,并且总匹配数应为4。我尝试过:
((jquery?)||(jQuery?)||(JQUERY?)||(Jquery))
but it gives me each word count individually.(ie jquery:1, jQuery:1, JQUERY:1, JQuery:1) 但是它给了我每个单词个数。(即jquery:1,jQuery:1,JQUERY:1,JQuery:1)
I need jquery:4 我需要jquery:4
My whole code: 我的整个代码:
var wordMatch = /((react?)|(angular?)|(javascript?)|(node?)|(mongo ?)|((jquery?)||(jQuery?)||(JQUERY?))|(backbone?))/gmi;
First, case insensitive matching is what the i
flag is for, and you're already using that. 首先,不区分大小写的匹配是i
标志的作用,您已经在使用它。 /jquery/i
will catch both jquery
and jQuery
, so you don't need so many options in your regex. /jquery/i
将同时捕获jquery
和jQuery
,因此您的正则表达式中不需要那么多选项。
Also, it's not clear what you're trying to do with the ?
另外,不清楚您要使用?
s, but it seems wrong. s,但这似乎是错误的。 ?
makes the preceding character or group optional, so /jquery?/
matches both jquery
and jquer
- probably not what you want. 使前面的字符或组为可选,因此/jquery?/
匹配jquery
和jquer
可能不是您想要的。
I think you're looking for 我想你在找
/(string)/gi
This will return all matches of "string" in the same group, not caring about casing. 这将返回同一组中所有“字符串”的匹配项,而不关心大小写。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.