Try a UDF
Function RemAlpha(str As String) As String
'Remove Alphas from a string
Dim re As Object
Set re = CreateObject("vbscript.regexp")
re.Global = True
re.Pattern = "\D"
RemAlpha = re.Replace(str, "")
End Function
Function RemDigits(str As String) As String
'Remove numbers from a string
Dim re As Object
Set re = CreateObject("vbscript.regexp")
re.Global = True
re.Pattern = "\d+"
RemDigits = re.Replace(str, "")
End Function
Gord
Just a few points, depending, of course, on what the OP really means. My guess is that your routines will satisfy his requirements, but I'm in a nit-pickey mood today
)
I assume by "alphabets" he means [A-Za-z].
Your first expression will remove all non-digits, not just the "alphabets".
Your second expression will remove all digits, leaving not only the "alphabets" but also various special characters.
So, the \D+ will serve to return all the digits.
But \d+ will return all non-digits, which can include punctuation, etc.
To only return the "alphabets" I would suggest [^A-Za-z]+