ctrlbrk
ctrlbrk

Reputation: 1194

RegEx to exclude an exact multi-word match

I need a RegEx to exclude a case insensitive exact match (entire string). If the entire string is "United States" (case insensitive) then I need to reject the string. If only part of the string contains "United States" (case insensitive) then it is fine.

I also need a minimum length of 6 characters for the string, if it is less than six it needs to reject the string.

I am having trouble with this because of the space between the words, and because I need to only exclude an exact match of this string and not a partial match.

This is for vBulletin and I am allowed only a single line regex for this form.

Upvotes: 1

Views: 2248

Answers (2)

Toto
Toto

Reputation: 91385

Why regex?

I'd do (in perl):

reject() if (uc($str) eq 'UNITED STATES' or length($str) < 6);

Upvotes: 0

stema
stema

Reputation: 92976

Your requirements are still a bit vague, but try

^(?i)(?!United States$).{6,}$

See it here on Regexr

^ Anchor to the start of the string

$ Anchor to the end of the string

(?i) inline option, making the regex match case insensitive

(?!United States$) negative lookahead, make the whole expression fail, if the string is from the start to the end only "United States"

.{6,} matches 6 or more characters

Upvotes: 3

Related Questions