C#
  Home arrow C# arrow Working with Regular Expressions in C#
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
C#

Working with Regular Expressions in C#
By: Barzan "Tony" Antal
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 9
    2008-08-19

    Table of Contents:
  • Working with Regular Expressions in C#
  • Working with RegExes
  • Working with RegExes, continued
  • Lots of Examples
  • Final Words

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Working with Regular Expressions in C#


    (Page 1 of 5 )

    Every now and then during our software development adventures we face situations where, if we are familiar with Regular Expressions, we could save ourselves a few minutes, if not more, of precious time. RegExes offer flexibility to identify, work with, and search for particular patterns or characters in strings. In this tutorial we are going to learn how to take advantage of Regular Expressions in C#.

    Regular expressions are widely used in various areas in computer sciences. Due to their popularity and usefulness, nowadays we can find regular expressions processors incorporated almost everywhere. Surely, the .NET framework doesn’t lack this kind of critical utility. However, to get the most out of RegExes, you need to fully understand their formal language, which is ubiquitous throughout interpreters.

    Interpreters are usually built into most programming languages and text editors. They are all based on the same formal language, which is quite concise and can become very complex at times. If you understand the basics and get some practice, however, you won’t have any trouble at all recognizing those patterns because they are pretty redundant and straightforward. Contrary to our first impressions, they do make sense.

    When, how, and why exactly should we work with regular expressions? Well, a regular expression processor (or interpreter) does all of the work instead of you, if you know how to communicate with it. This is the formal language that I was talking about. The processor works based on patterns. As long as you can phrase your requirements in this concise and formal syntax, then the processor will gladly help you out.

    As a result, this article shows you how to evoke the RegEx interpreter from the .NET Framework and how to do this appropriately in C#. After that it will focus mostly on examples, lots of examples, accompanied by illustrations. I will also include a table of the syntax that will contain most of the frequent regular expressions meta-characters. We will slowly move towards more complex examples after starting with the easier ones.

    Additionally, we won’t neglect the classes that are already included in the name-space we are going to use. Each one of them has lots of interesting built-in methods that can aid us throughout our coding (routine) tasks. In short, we need to learn two things from this article: how to work with RegExes and then how to format patterns. As soon as we excel in these two, all that there is left to do is practice—a lot. Enjoy!

    More C# Articles
    More By Barzan "Tony" Antal


       · Thanks for reading this article. Hopefully you've found it informative and...
     

    C# ARTICLES

    - C# and XML
    - Pointers and Arrays in C#
    - C# 3.0 Extension Methods
    - Overloading Operators in C#
    - Iterators and Nullable Types
    - Patterns and Iterators in C#
    - C# Exceptions
    - Methods in C#
    - Delegates and Events in C#
    - Advanced C#
    - Working with Regular Expressions in C#
    - Sending Simple E-Mail in C#
    - Building C# Comparable Objects: IComparable ...
    - Color Transformation Applications in C# GDI+...
    - Performing Color Transformation Operations i...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
    Stay green...Green IT