RappY
RappY

Reputation: 472

Match regex dont seperate uppercase or not uppercase

I have been searching on the site, but could not find an answer to my problem. I have a JavaScript regex pattern that matches some words and numbers. If I use a keyword "gemstone" and my input string has "Gemstone" in it, no match is found due to the fact that the word starts with an uppercase letter. How can I make the regex stop caring if a word contains uppercase letters? My current code:

var count =  (countDescription.match(new RegExp('(\\b)('+ u + ')(\\b)', 'g')) || []).length;

Upvotes: 1

Views: 175

Answers (1)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 627292

You should use the i option:

var count =  (countDescription.match(new RegExp('(\\b)('+ u + ')(\\b)', 'gi')) || []).length;

Upvotes: 1

Related Questions