Vigrant
Vigrant

Reputation: 1008

Regex for a word can be plural

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.

Upvotes: 2

Views: 4772

Answers (1)

emsimpson92
emsimpson92

Reputation: 1778

\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

Upvotes: 6

Related Questions