Navek
Navek

Reputation: 47

Don't match white space after word, but include when part of bigger string

I have the following regular expression:

\b(?!^Word1$|^Word2$|^Word3$|^Word4$)\b(?![\s]+)[a-zA-Z0-9\']{2,}

When a user types 'Word1' it doesn't match, which is what I want. When the user types 'Word1 foo' the whole string matches again, which is what I want.

However, when user types 'Word1 ' (note the space) the string matches. I'd like it to remain unmatched until another word is typed and then the whole line is matched.

Upvotes: 0

Views: 56

Answers (2)

Dimuth Lochana
Dimuth Lochana

Reputation: 249

This regular expression works only for strings with more than 1 word

\w*\s\w*

Upvotes: 1

Gibbs
Gibbs

Reputation: 22964

Demo

Very basic regex:

\w+[\s\w]*\w

It should match word and not word.

Upvotes: 1

Related Questions