Christopher Keeler
Christopher Keeler

Reputation: 191

regex literal pattern match with multiple words

Trying to match the literal word NEGATIVE (just by itself)

but my regex is also matching on these:

NEGATIVE

NEGATIVE DILUTE

How do I not have it not match at all when the phrase is NEGATIVE DILUTE or any other phrase besides just NEGATIVE

This is in jQuery and my regex so far is this:

    /\bNEGATIVE\b/i

Any help is appreciated.

Upvotes: 0

Views: 1767

Answers (2)

CorrugatedAir
CorrugatedAir

Reputation: 819

Use ^ to indicate that the regex should start at the beginning of the string and $ to indicate the end of the match must equal the end of the string:

^NEGATIVE$

Upvotes: 0

Michael
Michael

Reputation: 3332

^NEGATIVE$

This will match NEGATIVE, and will not match if there is anything before or after it. Basically, if the string only contains the phrase and nothing else.

Here's a site that will explain this regex and any others you input: http://www.regex101.com/r/iA7fY5

Upvotes: 2

Related Questions