Boost Your .NET Projects: Maximize Your .NET Performance with Spargine’s RegexProcessor

Spargine is a set of open-source assemblies and NuGet packages for .NET 8, developed and maintained by me since the release of .NET 2. These assemblies are integral to my projects and are currently in production at my company. You can access the source code and NuGet packages through the following links:

The RegexProcessor class in the DotNetTips.Spargine.8.Core assembly provides a set of powerful methods to process text efficiently using regular expressions. Leveraging the GeneratedRegexAttribute and code generation, this class is optimized for performance.

Methods

The RegexProcessor class offers utility methods for common string operations involving regular expressions. Below is an overview of the available methods:

  • ContainsFirstLastName()
    Checks if the given input contains both a first and last name.
  • ContainsWord()
    Determines if the input contains a specific word.
  • GetNumbers()
    Extracts all numeric characters from the input string.
  • IsCreditCardNumber()
    Verify whether the input is a valid credit card number.
  • IsCurrencyCode()
    Checks whether the input represents a valid currency code.
  • IsEmailAddress()
    Validates if the input is a correctly formatted email address.
  • IsGuid()
    Determines whether the input is a valid GUID (Globally Unique Identifier).
  • IsIPv4Address()
    Checks if the input is a valid IPv4 address.
  • IsIPv6Address()
    Checks if the input is a valid IPv6 address.
  • IsISBN()
    Validates whether the input is an ISBN (International Standard Book Number).
  • IsMACAddress()
    Determines if the input is a valid MAC (Media Access Control) address.
  • IsOneToSevenAlpha()
    Determines if the input string contains only alphabetic characters and has a length between 1 and 7 characters.
  • IsScientific()
    Determines if the input string is in scientific notation.
  • IsSHA1Hash()
    Checks if the input is a valid SHA-1 hash.
  • IsUrl()
    Verifies if the input is a valid URL.
  • IsUrlDomainAddress()
    Determines whether the input contains a valid URL domain address.
  • IsValidString()
    Checks whether the input is a valid string based on certain criteria.
  • RemoveHtml()
    HTML tags are removed from the input string and replaced with the specified replacement text.
  • RemoveSpecialChar()
    Removes special characters from the input string, replacing them with the specified replacement text.
  • ReplaceCrLf()
    Replaces carriage return (CR) and line feed (LF) characters in the input string.
  • ReplaceSpaces()
    Replaces spaces in the input string with the specified replacement character.

Source Generator vs. Conventional Methods for Regular Expressions

Is using a source generator faster for handling regular expressions in .NET? Let’s compare the performance of three different approaches to utilizing regular expressions. When employing a source generator, a regular expression that checks for the presence of a specific word in a string performs 11 times faster than when using a precompiled field, and a remarkable 86 times faster than invoking the regular expression in the conventional, on-the-fly manner.

Contribution

If you’re utilizing RegexProcessor and notice any missing functionality, feel free to submit a feature request on GitHub. I’ll work to incorporate it into the project as soon as possible.

Summary

I am confident that these enhanced methods in Spargine will greatly benefit your projects by improving performance and reliability. Detailed benchmark results are available on GitHub. The success of open-source projects like Spargine depends significantly on community involvement. If you find these updates useful or have ideas for further improvements, I encourage you to contribute. Whether by submitting a pull request, reporting issues, or suggesting new features, your input is invaluable.

Together, we can continue to make Spargine a powerful and essential tool for the .NET community. Your feedback and suggestions are highly appreciated, so please share them in the comments section.

If you are interested in contributing to this project or have any questions, feel free to contact me via email at dotnetdave@live.com. Your support and collaboration are greatly appreciated!

Thank you for your support, and happy coding!

Pick up any books by David McCarter by going to Amazon.com: http://bit.ly/RockYourCodeBooks

One-Time
Monthly
Yearly

Make a one-time donation

Make a monthly donation

Make a yearly donation

Choose an amount

$5.00
$15.00
$100.00
$5.00
$15.00
$100.00
$5.00
$15.00
$100.00

Or enter a custom amount

$

Your contribution is appreciated.

Your contribution is appreciated.

Your contribution is appreciated.

DonateDonate monthlyDonate yearly

If you liked this article, please buy David a cup of Coffee by going here: https://www.buymeacoffee.com/dotnetdave

© The information in this article is copywritten and cannot be preproduced in any way without express permission from David McCarter.


Discover more from dotNetTips.com

Subscribe to get the latest posts sent to your email.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.