> I want to parse a string, ONLY allowing alphanumeric characters and
> also the underscore '_' and dash '-' characters.
[quoted text clipped - 4 lines]
>
> ^([\w\d_-])*$
^[\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
DotNetNewbie - 27 Feb 2008 15:39 GMT
> > I want to parse a string, ONLY allowing alphanumeric characters and
> > also the underscore '_' and dash '-' characters.
[quoted text clipped - 20 lines]
>
> Arne
Replace doesn't take only 2 arguements, that doesn't work?
Arne Vajhøj - 28 Feb 2008 01:23 GMT
>>> I want to parse a string, ONLY allowing alphanumeric characters and
>>> also the underscore '_' and dash '-' characters.
[quoted text clipped - 14 lines]
>
> Replace doesn't take only 2 arguements, that doesn't work?
There are 3 arguments in the call I suggest.
And Regex.Replace does have such a method:
http://msdn2.microsoft.com/en-us/library/e7f5w83z.aspx
Arne