DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Design Automation in Closure Engineering: Building Parametric Assemblies With CATIA and VB Scripting
  • The Hidden World of Exit Codes: Tiny Integers With Big Meanings
  • Importing multiple extension assemblies in C# with MEF
  • 3 Examples of Address Autofill Forms to Collect Shipping and Payment Addresses

Trending

  • New York City Taxi Trips: Putting Neo4j and DuckDB to Work
  • When a Coding Agent Fixes the Test Instead of the Bug
  • Member Spotlight: Shai Almong
  • How to Build Your Own AI SRE From Scratch

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

How to run regular expressions faster in C#

By 
Senthil Kumar
·
Apr. 08, 15 · Interview
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
6.5K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

If you want the regular expression to run faster , you can set the RegexOptions.Compiled value to the regex constructor. This will compile the regex in to their own assembly which will run a little faster.

Below is a sample code snippet demonstrating the usage of RegexOptions.Compiled.

//  Validating a Zip codes in C# using Regular Expression
2
string GKZipCode = @"^\d{5}(-?\d{4})?$";
3
Regex regex = new Regex(GKZipCode, RegexOptions.Compiled);
4
bool Matching = regex.IsMatch("15689");
5
Console.WriteLine(Matching);
6
Console.ReadLine();


Snippet (programming) Assembly (CLI)

Published at DZone with permission of Senthil Kumar. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Design Automation in Closure Engineering: Building Parametric Assemblies With CATIA and VB Scripting
  • The Hidden World of Exit Codes: Tiny Integers With Big Meanings
  • Importing multiple extension assemblies in C# with MEF
  • 3 Examples of Address Autofill Forms to Collect Shipping and Payment Addresses

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook