I'm trying to use .NET Regex.Replace (example here in VB.NET) to exclude all non-chars and spaces from a string. For instance, in the string s below, I thought the pattern [^A-z ] should remove all non-alphabets aside from spaces. However, that doesn't seem to work. What am I doing wrong?
Sub Try_Regex_Remove_Caret_Symbol()
' ^ (caret) character is not being removed via exclusion
Dim s As String, p As String
s = "I have a caret which I want removed ^$@#!&"
p = "[^A-z ]"
Console.WriteLine("Input : " & s)
Console.WriteLine("Output: " & Regex.Replace(s, p, ""))
' Input : I have a caret which I want removed ^$@#!&
' Output: I have a caret which I want removed ^
' Note that the caret (^) is not removed as expected
End Sub