Re: Parsing a string, removing any NON alphanumeric characters using regex
- From: Arne Vajhøj <arne@xxxxxxxxxx>
- Date: Tue, 26 Feb 2008 18:28:22 -0500
DotNetNewbie wrote:
I want to parse a string, ONLY allowing alphanumeric characters and> ^([\w\d_-])*$
also the underscore '_' and dash '-' characters.
Anything else in the string should be removed.
I think my regex is looking like:
^[\w-]*$
should do - \w includes digits and underscore.
Now if I have this code:
string username = "mrcsharpis_so_cool!!!";
How can I strip all the characters that I dont' want?
Try:
Regex.Replace(username, @"[^\w-]+", "")
Arne
.
- Follow-Ups:
- Re: Parsing a string, removing any NON alphanumeric characters using regex
- From: DotNetNewbie
- Re: Parsing a string, removing any NON alphanumeric characters using regex
- References:
- Parsing a string, removing any NON alphanumeric characters using regex
- From: DotNetNewbie
- Parsing a string, removing any NON alphanumeric characters using regex
- Prev by Date: Parsing a string, removing any NON alphanumeric characters using regex
- Next by Date: Re: Only allowing alphanumeric characters and '_' and '-'
- Previous by thread: Parsing a string, removing any NON alphanumeric characters using regex
- Next by thread: Re: Parsing a string, removing any NON alphanumeric characters using regex
- Index(es):
Relevant Pages
|