Digital Point Forums
Wester Union

Go Back   Digital Point Forums > Design & Development > Programming > ASP
Google Analytics
Log In to view
your analytics

Reply
 
Thread Tools
  #1  
Old Nov 3rd 2009, 2:15 pm
tmbtech tmbtech is offline
Grunt
 
Join Date: Feb 2009
Posts: 56
tmbtech is on a distinguished road
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
Reply With Quote
  #2  
Old Nov 5th 2009, 3:07 am
yugolancer's Avatar
yugolancer yugolancer is offline
Hand of A'dal
 
Join Date: Jun 2007
Location: http://www.itsoknow.com/
Posts: 300
yugolancer is on a distinguished road
where that string comes from? Is it textbox entry, database record, hardcoded string variable ....?
Reply With Quote
  #3  
Old Nov 5th 2009, 9:49 am
tmbtech tmbtech is offline
Grunt
 
Join Date: Feb 2009
Posts: 56
tmbtech is on a distinguished road
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 @
Reply With Quote
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


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


All times are GMT -8. The time now is 6:34 am.