admin管理员组文章数量:1406937
I want regex that will match "lead" or "leads" and will not match when it's part of another word like cheerleaders or leaders. I also don't want whitespaces matched before or after the word.
The closet I got was /(?:^|\W)Lead(?:$|\W){0,5}/g;
But this matches Leaders and whitespaces. This is in javascript if that makes a difference.
I want regex that will match "lead" or "leads" and will not match when it's part of another word like cheerleaders or leaders. I also don't want whitespaces matched before or after the word.
The closet I got was /(?:^|\W)Lead(?:$|\W){0,5}/g;
But this matches Leaders and whitespaces. This is in javascript if that makes a difference.
Share Improve this question asked Aug 13, 2018 at 18:09 VigrantVigrant 1,0182 gold badges18 silver badges29 bronze badges 5- is "lead" the only word or do you mean any word? – emsimpson92 Commented Aug 13, 2018 at 18:10
- lead is the only word. – Vigrant Commented Aug 13, 2018 at 18:11
-
\bleads?\b
is what you want then – emsimpson92 Commented Aug 13, 2018 at 18:11 - Not on my end – emsimpson92 Commented Aug 13, 2018 at 18:12
- yep that works. go ahead and answer. – Vigrant Commented Aug 13, 2018 at 18:13
1 Answer
Reset to default 6\bleads?\b
is all you need. \b
is a word boundary, which means the word ends at the boundary.
s?
is an optional s
Demo
本文标签: javascriptRegex for a word can be pluralStack Overflow
版权声明:本文标题:javascript - Regex for a word can be plural - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745052578a2639740.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论