I'm throwing an updated answer as it was brought to my attention that this was posted in the Visual Basic forum so I'll provide the same answers but with Visual Basic syntax :
To Remove Non-Numerical Characters:
Dim numericOnly As String = Regex.Replace(yourString, @"[^\d]", "")
or in method form :
Function NumericOnly(ByVal yourString As String) As String { Dim numericOnly As newRegex(@"[^\d]") return numericOnly.Replace(yourString,"") }
To Remove All Non-Alphabetic:
Dim alphabeticOnly As String =Regex.Replace(yourString,@"[^a-zA-Z]","")
and as a method :
Function AlphabeticOnly(ByVal yourString As String) As String { Dim alphaOnly =newRegex(@"[^a-zA-Z]") return alphaOnly.Replace(yourString,"") }
dch3
Member
447 Points
638 Posts
RegEx Needed Please
Jan 15, 2013 01:15 AM|LINK
I am in search of a RegEx that will strip out all non-numeric characters returning only the numeric characters.
2301 Returns 2301
2301-A Returns 2301
ABCD Returns [Zero Length String]
~!@#$%^&*()_+|}{":?><`-=[]\';/., Returns [Zero Length String]
And now that I thnk about it, also a second RegEx that strips out everything that is not a letter [A-Z][a-z].
Rion William...
All-Star
26694 Points
4414 Posts
Re: RegEx Needed Please
Jan 15, 2013 01:18 AM|LINK
To Remove Non-Numerical Characters:
or in method form :
string NumericOnly(string yourString) { Regex numericOnly = new Regex(@"[^\d]"); return numericOnly.Replace(yourString, ""); }To Remove All Non-Alphabetic:
and as a method :
string AlphabeticOnly(string yourString) { Regex alphaOnly = new Regex(@"[^a-zA-Z]"); return alphaOnly.Replace(yourString, ""); }Rion William...
All-Star
26694 Points
4414 Posts
Re: RegEx Needed Please
Mar 07, 2013 09:55 PM|LINK
I'm throwing an updated answer as it was brought to my attention that this was posted in the Visual Basic forum so I'll provide the same answers but with Visual Basic syntax :
To Remove Non-Numerical Characters:
or in method form :
To Remove All Non-Alphabetic:
and as a method :