Jason94 Jason94 - 5 months ago 29
C# Question

Regex to only match words without special symbols or numbers

I'm trying to figure out how to match "word" but not "word1", "w1ord" or any variation of "word!" where "!" could be anything "#%!"

Basically I want to match against word that only uses A-Z and a-z. The following does not work :/


As "word%5" is a match.

bool notOnlyLetters = yourStringValue.ToArray().Any(x => !(x >= 65 && x <= 122));

You can do it with linq

EDIT: After second correct edit of Wiktor.

bool notOnlyLetters = yourStringValue.ToUpper().ToArray().Any(x => !(x >= 65 && x <= 90));