EASY REGULAR EXPRESSIONS IN C#
I really love using regular expressions.
It's so easy to check strings... for example if you want only alphanumeric or only numbers or a very specific format like two letters, one point, one number and a #, in the specific order.
In my opinion, it's highly difficult to create the reg exp from scratch.
I have found a very good shareware program which build and test them for me. You can find it here.
Once you have your regular expression, how can you use it in your code?
Let's say you just need to check if a string is composed only by alphanumeric chars.
Here's a bit of C# code:
string mystring = "HELLO";
string regExpString = "^\\w+$";
if (System.Text.RegularExpressions.Regex.IsMatch( mystring , regExpString))
//here mystring contains only alphanumerics
else
// here mystring contains also something else
So... isn't it easy?
It's so easy to check strings... for example if you want only alphanumeric or only numbers or a very specific format like two letters, one point, one number and a #, in the specific order.
In my opinion, it's highly difficult to create the reg exp from scratch.
I have found a very good shareware program which build and test them for me. You can find it here.
Once you have your regular expression, how can you use it in your code?
Let's say you just need to check if a string is composed only by alphanumeric chars.
Here's a bit of C# code:
string mystring = "HELLO";
string regExpString = "^\\w+$";
if (System.Text.RegularExpressions.Regex.IsMatch( mystring , regExpString))
//here mystring contains only alphanumerics
else
// here mystring contains also something else
So... isn't it easy?

1 Comments:
Are you interested in link exchange...??
I have few blogs ready for link exchange..
just have a look at them:
Free Ebooks Download
Free Hindi Songs Download
Free English Songs Download
Tips For Bloggers
it would help both of us..
If interested contact me at:: spectrojin@yahoo.co.in
or write a comment on any of my above blogs.
please mention your blog/site URL and title while replying
thanx in advance...
By
crasher, At
March 29, 2008 12:11 PM
Post a Comment
<< Home