Home About

 March 11th, 2009

Advanced Regular Expressions in C# - 12

Regular Expressions in C# - Advanced Topics
In this third and for now last post on using regular expressions we look at some advanced topics. When your expressions become more complicated they also become harder to understand so documenting them can help. And isn’t standard string replacement a little bit too basic? We also look at how speeding things up can improve your code’s efficiency.

In this post we look at three topics:

  1. Improving your code’s readability by documenting regular expressions
  2. Creating conditional string replacement by using MatchEvaluators
  3. Speeding up regular expressions by compiling them, caching them in memory and pre-compiling them to their own DLL.

If you are new to regular expressions in C# have a look at the theory of regular expression in Regular Expressions : The Basics. The second post Regular Expressions in C#: Practical Usage introduced the most common uses of regular expressions.

Read the rest of this entry »

 March 10th, 2009

Regular Expressions in C# – Practical Usage - 6

Regular Expression - Practical Usage

This is the second post in the C# regular expression series and it follows up on “Regular Expressions in C# – The Basics” which explained the theory behind Regular expressions in C#. In this post we look at how to make practical use of regular expressions in our C# code.

This post touches on four major regular expression subjects:

  • String Comparison – does a string contain a particular sub-string?
  • Splitting a string into segments – we will take an IPv4 address and retrieve its dotted components
  • Replacement – modifying an input string
  • Stricter input validation – how to harden your expressions

Read the rest of this entry »

 March 9th, 2009

Regular Expressions in C# – The Basics - 7

Regular Expressions in C#

One of the most common coding tasks is to take an input, munch it around and turn it into something different altogether. Are you looking for FedEx numbers in a text file? Do you want to replace “love” with “hate” in your source files? Is a string a valid e-mail address? Problems like these can be solved by applying regular expressions, or “regex” for short.
Read the rest of this entry »

 March 6th, 2009

C# Regular Expression Cheat Sheet - 2

I have been doing quite a bit with regular expressions recently and to avoid having to look them up again and again I made myself a little table with the most important C# regular expression operators and stuck it on the wall. This post contains the C# regular expression operators as used by the .NET regular expression classes such as RegEx.

If you would like to print this, click here for a pure HTML version.

Read the rest of this entry »


Most popular

    Sorry. No data so far.

Recent Comments
  • Juan Romero: Hi there, it’s a neat little class, but I believe you could do the same thing with the WebClient...
  • anthosh: Hey, THank you very much for your tutorial. It was awesome. But i have a problem that i am not able to...
  • bian: how to get passphase if i have encrypt and decrypt string?? Thanks alot
  • Michael: Hi, I really like your post, thanks a lot, it really helped clear up a few things I could not remember how...
  • Bharat Prajapati: i was trying to import keyword dictionary to this plugin which is in csv format, but i get an error...