user1318106 user1318106 - 1 month ago 8x
ASP.NET (C#) Question

Regular expression to restrict less than <,greater than > and semicolon ; character

I need a regular expression to restrict the < less than, greater than > and ; semicolon sign.

I have used the below regular expression to restrict the less than and greater than sign but I need to include the semicolon ; sign as well.


Any help will be appreciated.


This is pretty easy to achieve if you read very little about regex. The feature you are using is the character class and you can learn more about this here

Related to your regex is quite simple, in this case you are using a negated character class by [^...] so you have just to add the semicolon to it:


Regular expression visualization