Need a regular expression that will not allow a string to be "COM"

groadsvb

Well-known member
Joined
Nov 13, 2006
Messages
75
Programming Experience
Beginner
This expression will be used to validate codes that can be up to 10 characters long, but it cannot be the code of "COM" anything else is ok. I have tried a few things but not quite there. Any suggestions will be great.
 
Dim pattern = "^((?!COM).){10}$"

That is a start of string, negative lookahead and match any char (grouped), repeat group 10 times, end of string. Regular-Expressions.info - Regex Tutorial, Examples and Reference

You can also just use the String class for validating such a simple pattern (String.Length and Not String.Contains).
 
Back
Top