Regular Expression pattern issue

Total Post:154


 2102  View(s)
Rate this:

I want to delete all the characters other than letter and number from a given string. I used the pattern below but it still returns string without any change.

Regex rex = new Regex("/[^a-zA-Z0-9]+/");

Response.Write(rex.Replace("asd123!-<>@;',.", ""));

It suppose to return "asd123"

Regex patterns are like alien language to me and I dont know how to fix this.


  1. Re: Regular Expression pattern issue

    Hi Manoj,

    In C#, you don't need to delimit regex patterns with / characters.

    Try this:

    Regex rex = new Regex("[^a-zA-Z0-9]+");
    Response.Write(rex.Replace("asd123!-<>@;',.", ""));

      Modified On Apr-04-2018 01:13:59 AM


Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.