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?
