Jaymond Flurrie
Well-known Member
- Joined
- Sep 22, 2008
- Messages
- 921
- Office Version
- 365
- Platform
- Windows
Using Microsoft VBScript Regular Expressions 5.5.
I'm pretty close with this one, but shortly, I want to allow numbers, letters (including ÅÄÖ) and underscores. I don't want to allow special characters, like ^ or $. So the not allowed characters should simply be removed. I have a problem with that $ now, I understood that's the "end of string to test", so I think I'm supposed to include it somehow there.
This is what I have:
I'm pretty close with this one, but shortly, I want to allow numbers, letters (including ÅÄÖ) and underscores. I don't want to allow special characters, like ^ or $. So the not allowed characters should simply be removed. I have a problem with that $ now, I understood that's the "end of string to test", so I think I'm supposed to include it somehow there.
This is what I have:
VBA Code:
Sub testparsename()
Dim result As String
result = ParseName("^Test$") 'This returns now Test$
End Sub
Public Function ParseName(original As String) As String
Dim searchpattern As String:
searchpattern = "[^0-9A-ZÅÄÖ_$]"
Dim replacewith As String
replacewith = vbNullString
Dim result As String
Dim regEx As New RegExp
With regEx
.Global = True
.MultiLine = True
.IgnoreCase = True
.Pattern = searchpattern
result = .Replace(original, replacewith)
End With
ParseName = result
End Function