Home > DeveloperSection > Forums > Regular Expression pattern issue
Manoj Bhatt
Manoj Bhatt

Total Post:154

Posted on    December-27-2013 6:59 AM

 C# C# 

 1 Reply(s)
 1593  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.


Alex Leblois
Alex Leblois

Total Post:67

Posted on    December-27-2013 7:42 AM

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!-<>@;',.", ""));

Don't want to miss updates? Please click the below button!

Follow MindStick