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
Over 2 million developers have joined DZone.
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

  • How to Format Articles for DZone
  • Artificial Intelligence in Architecture
  • Machine Identity Debt: Why Human Identity Is No Longer Cloud Security's Primary Boundary
  • Observability Fundamentals Beyond Traditional Monitoring

How to run regular expressions faster in C#

By 
Senthil Kumar user avatar
Senthil Kumar
·
Apr. 08, 15 · Interview
Likes (1)
Comment
Save
Tweet
Share
6.5K Views

Join the DZone community and get the full member experience.

Join For Free

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

The likes didn't load as expected. Please refresh the page and try again.

  • 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