Click here to Skip to main content
15,891,204 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
i have string of arrays that contains texts like

abcdefghi

a.bec0123

hijk.2.3lmop

strin458


now how can i write a regular expression that if the text doesnot contains any special characters then i have to replace the text with the "" eg:"strin458"

Thanks in advance
Posted

I wouldn't necessarily try to do this completely with a regex:
C#
string myString = "string56";
Regex r = new Regex(@"[\.\:\""\'\\]");
if (!r.IsMatch( myString ))
    {
    myString = string.Format( @"""{0}""", myString );
    }
Console.WriteLine( myString );
 
Share this answer
 
Have a look at this great RegExp online editor and tester:
http://gskinner.com/RegExr/[^]

It's a fabulous tool though it does take a bit of getting used to it has recently basically taught me RegExp. Just try playing around with different things! The side bar contains all the RegExp symbols, escaped characters, expressions etc and examples that you need to produce really complex RegExp. It even highlights matches for you and will let you do find and replace tests to. It also 'tests as you type' :) Final thing is that it will split your expression up for you to show the different groups and any errors.

Hope this helps,
Ed :)
 
Share this answer
 
Comments
sachin10d 27-Sep-11 2:37am    
good link!!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900