.NET Regular Expression

How would I write a regular expression (C #) that will check the given string to see if any of its characters have OTHER characters than the following:

ah
AZ
Æ æ Å ø Ø ø - '

+4
source share
2 answers
new Regex("[^a-zA-ZÆæÅ娸'-]") 

[] creates a character class, then ^ indicates the negation, so the character corresponds to the class if it is not one of those listed.

+12
source

To achieve this, you can use character grouping in combination with the negation operator.

You also need to escape the character - (and possibly ') by using \

Your final expression will read:

[^ A-Za-ZÆæÅ娸 \ - \ '] *

+1
source

Source: https://habr.com/ru/post/1311293/


All Articles