Home > Articles > Programming > .NET and Windows Programming

Programming with Regular Expressions in C#

Paul Kimmel
  • PrintPrint
  • Share ThisShare This
  • DiscussDiscuss
Close WindowPaul Kimmel

Paul Kimmel

Learn more…

Debugging Client-Side JavaScript for ASP.NET with Visual Studio
Sep 16, 2009
Using Entity SQL As Your Data Access Layer
Dec 2, 2008
Programming with LINQ to XML for Objects
Nov 21, 2008
Bill Wagner on C#, LINQ, and Writing Books
Oct 6, 2008
Writing LINQ Queries with the Entity Framework
Sep 23, 2008
Using Parallel LINQ
Aug 15, 2008
Programming with Anonymous Types in C#
Aug 11, 2008
Querying SQL with LINQ
Jul 28, 2008
Writing Lambda Expressions in the .NET Framework
Jun 11, 2008
Programming with Generic Delegates in .NET
May 8, 2008
Managing Database Transactions with the TransactionScope
Sep 7, 2007
Letting ADO.NET Write Your SQL
Jun 8, 2007
Using C#'s yield to Return an Enumerable Collection
Apr 27, 2007
Using the My Feature in Visual Basic .NET
Sep 8, 2006
Programming with the BackgroundWorker Component in .NET 2.0
Apr 7, 2006
How to Use Partial Classes in Visual Studio 2005
Jan 13, 2006
Generic Classes in C# 2.0
Nov 11, 2005
Anonymous Methods in C# 2.0
Oct 28, 2005
Implementing an XML Section Handler in .NET
Sep 16, 2005
.NET Remoting: Handling Remote Server Events
Feb 11, 2005
Converting XML Nodes into Objects
Dec 10, 2004
Using Application Blocks for Data Access
Oct 22, 2004
A Roll of the Dice: Building a Small Game Using Windows Graphics Programming
Oct 1, 2004
Through the Looking Glass: Debugging Hosted .NET Applications
May 13, 2004
Listening to Trace Messages in NUnit
May 7, 2004
Instrumenting Your Code for Exception Management
Dec 23, 2003
What's .NET Remoting, And Why Should You Care?
Dec 12, 2003
Injecting Dynamic JavaScript to Focus ASP.NET Controls
Oct 10, 2003
Defining Add and Remove Accessor Methods for Events in VB.NET
Apr 18, 2003
Debugging .NET with NUnit
Mar 14, 2003
Dynamic Debug Code Management with BooleanSwitches
Feb 28, 2003
Creating Typed DataSets with XML Schemas
Jan 24, 2003
Fall Comdex 2002: .NET or .What?
Jan 10, 2003
Managing Session State for ASP.NET
Nov 15, 2002
Creating Project Templates in .NET
Oct 25, 2002
Creating Custom Attributes in Visual Basic .NET
Oct 11, 2002
Asynchronous Web Services
Sep 20, 2002
Inheritance and Polymorphism in VB.NET
Aug 9, 2002
Serializing Objects to a .NET DataSet
Jul 19, 2002
Implementing the Strongly Typed Collection in C#
Jul 5, 2002
Emitting MSIL with Reflection
Jun 28, 2002
Programming with Regular Expressions in C#
Jun 21, 2002
Creating Data-Enabled Web Pages using the DataList
Mar 8, 2002
Creating Visual Studio .NET Add-Ins
Mar 8, 2002
Lightweight Threading with Thread Pools in Visual Basic .NET
Mar 8, 2002
Understanding Delegates in Visual Basic .NET
Mar 8, 2002
Working with New Abstract Data Types in Visual Basic .NET
Mar 8, 2002
Storing Your Access Data
Feb 8, 2002
Adding Data to Web Pages
May 11, 2001

Sorry, this author hasn't posted any blogs.

Visual Basic .NET Unleashed

From the author of
Visual Basic .NET Unleashed

Visual Basic expert Paul Kimmel demonstrates how to use regular C# expressions to emit dynamic assemblies containing regular expressions and how to save time and programming effort.

Compiling Regular Expressions

.NET uses a nondeterministic finite automation (NFA) engine to parse and analyze regular expressions. This approach is consistent with the regular expression engine found in Perl 5. The NFA engine is used by default, but if you initialize a Regex object with the RegexOptions.Compiled option your regular expression will converted and compiled to a .NET equivalent. Compiled regular expression code runs noticeably faster than code that uses the NFA engine. How much faster in a practical application is something that you can experiment with. If your application is running hundreds or thousands of expressions, such as in a search engine, it may be worthwhile to compile the regular expressions.

Additionally, you can use an emitter—part of .NET Reflection—to emit a custom regular expression class to a dynamic assembly. The final section of this article demonstrates how to use the Regex.CompileToAssembly static method to emit regular expressions to an external assembly.

  • Share ThisShare This
  • Your Account

Discussions

Make a New Comment

You must log in in order to post a comment.

Related Resources

Danny KalevMinutes from the October 2009 Meeting
By Danny Kalev on November 19, 2009 No Comments

The minutes from the Santa Cruz (October 2009) meeting are available here. Even if you're not a language layer at heart, I encourage you to read them.

Danny KalevA Reader's Opinion on Attributes
By Danny Kalev on October 20, 2009 No Comments

In August I dedicated a series to the debate about C++0x attributes. I believe that it covered the subject in a balanced and detailed way, but I keep getting complaints from C++ users who don't like attributes for various reasons. Here's a recent email I received from a Polish C++ programmer. While it  doesn't represent my opinion about attributes -- I'm rather neutral about this feature and consider it a "solution waiting for a problem" -- but it suggests that attributes are still a highly controversial issue that will haunt C++ for a long time. The email is quoted here with minor edits that and as usual, with all private details removed.

Danny KalevFollowup: The Web 2.0 Guy I Ain't
By Danny Kalev on October 16, 2009 1 Comment

Almost a year ago, I posted here The Web 2.0 Guy I Ain't. People wonder whether I still resist all those Web 2.0 features and technologies at the end of 2009.

See All Related Blogs

Informit Network