![]() |
|
|
#1
|
|||
|
|||
|
Regular Expression c# format string
Hello,
I'm trying to create a regular expression that will reformat a string. basically I only want to allow a-z A-Z 0-9 a space and an "x" so if there are any other char found it should remove it from the string Does anyone know the best way to do this besides just looping through the string and removing the unwanted char |
|
#2
|
||||
|
||||
|
where that string comes from? Is it textbox entry, database record, hardcoded string variable ....?
|
|
#3
|
|||
|
|||
|
just a variable somewhere.
I figured it out, here is the code just in case anyone wants to use it. string pattern = @"[^A-Za-z0-9\s@.]"; Regex rgx = new Regex(pattern); string inputStr = "2o3423u 09809283 asdjflj 39!@#$%^@#$099248"; string outputStr = rgx.Replace(inputStr, ""); I changed the code to allow alphanumeric, space, dot, and @ |
![]() |
| Bookmarks |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Reg Expression - Fetch string between 2 characters | lbalance | JavaScript | 2 | Aug 28th 2009 8:41 pm |
| Regular expression help | PHP dev | PHP | 15 | Oct 27th 2008 11:39 pm |
| Regular Expression Help | trixs | Programming | 1 | Apr 20th 2008 11:06 am |
| Regular Expression Q. | alphacooler | PHP | 3 | Jun 30th 2007 9:01 pm |
| What does this regular expression mean? | hajamie | PHP | 0 | Oct 7th 2005 10:58 am |