Jason94 Jason94 - 23 days ago 6
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 :/

([A-Za-z])\w+


As "word%5" is a match.

Answer
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));