Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Regex should not match if a value has a dot

I want to check if a variable is in any of a set of words. For example

'Guava'.match(/\b(apple|mango|orange)\b/ig);

The above does not match, which is correct.

'AppleA'.match(/\b(apple|mango|orange)\b/ig)

This too does not match. Again correct.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

'Apple.A'.match(/\b(apple|mango|orange)\b/ig)

This however returns a match, which is not what I want. How do I fix this?

I want a match only if the value is Apple OR apple OR mango OR mAngo, etc.

>Solution :

Try this

'Apple.A'.match(/^(apple|mango|orange)$/ig)

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading