Using C# Regular Expression

Many helpful details can be found here Using Regular Expressions with .NET – C# and Visual Basic

 

Matching multiple line?

This is a topic that hard to find one article for it. If you have one, please shared with me!

Replacing that re-uses searched text

Look at this example:

//remove multiple white-spaces

System.Text.RegularExpressions.Regex re = new System.Text.RegularExpressions.Regex(@"(\s)\s+");

myString = re.Replace(myString, "$1");

As we can see, we use $1 to retriev the searched text reside in the 1st parentheses. So the rule is to use $# with # is the order number of the parentheses used in the regular expression. Enjoy!

//remove multiple white-spaces System.Text.RegularExpressions.Regex re = new System.Text.RegularExpressions.Regex( @”(\s)\s+” ); ret = re.Replace(ret, “$1”);
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: