GithubHelp home page GithubHelp logo

forkfunny / regextoolbox.net Goto Github PK

View Code? Open in Web Editor NEW

This project forked from markwhitaker/regextoolbox.net

0.0 0.0 0.0 255 KB

Regular expression tools for .NET developers

License: Apache License 2.0

C# 100.00%

regextoolbox.net's Introduction

icon

RegexToolbox.NET Build and test Publish to NuGet NuGet Version and Downloads count

Regular expression tools for .NET developers.

RegexBuilder

RegexBuilder is a class for building regular expressions in a more human-readable way using a fluent API. It offers a number of benefits over using raw regex syntax in strings:

  • No knowledge of regular expression syntax is required: just use simple, intuitively-named classes and methods.
  • Code is easier to read, understand and maintain.
  • Code is safer and far less prone to regular expression syntax errors and programmer errors.

Here's an example:

var regex = new RegexBuilder()
    .Text("Hello")
    .Whitespace(RegexQuantifier.OneOrMore)
    .Text("world!")
    .BuildRegex();

But that's just a taste of what RegexBuilder does: for full API documentation, head over to the project wiki.

Breaking changes in 2.0

All RegexBuilder features that were deprecated in version 1.6 have been removed in 2.0.

Removed Replaced with
StartGroup()...EndGroup() Group()
StartNamedGroup()...EndGroup() NamedGroup()
StartNonCapturingGroup()...EndGroup() NonCapturingGroup()
AddLogger() No replacement: logging has been removed.

New in 1.6

Improved grouping methods

Version 1.6 introduces a simplified syntax for cleaner, less error-prone creating of groups. Go from this:

var regex = new RegexBuilder()
    .StartGroup()
    .Letter()
    .Digit()
    .BuildRegex(); // ERROR: forgot to call EndGroup()

to this:

var regex = new RegexBuilder()
    .Group(r => r
        .Letter()
        .Digit()
    ) // Yay! Can't forget to end the group
    .BuildRegex();

There are also new NamedGroup() and NonCapturingGroup() methods.

The old methods StartGroup(), StartNamedGroup(), StartNonCapturingGroup() and EndGroup() have been deprecated and will be removed in version 2.0.

More powerful AnyOf() overloads

The AnyOf() method is used to match any of a set of alternatives. Previously it only let you specify strings as the alternatives, for example:

var animalLoverRegex = new RegexBuilder()
    .Text("I love ")
    .AnyOf("cats", "dogs", "tortoises")
    .BuildRegex();

Now you can specify arbitrarily complex sub-regexes as the alternatives, such as:

// Match 3 letters followed by a full stop OR 4 digits followed by a comma
// (for some weird reason)
var regex = new RegexBuilder()
    .AnyOf(
        r => r
            .Letter(Exactly(3))
            .Text("."),
        r => r
            .Digit(Exactly(4))
            .Text(",")
    )
    .BuildRegex();

New string extension method

string.Replace(Regex regex, string replacement)

Logging deprecated (removed in version 2.0)

The logging feature introduced in version 1.3 wasn't proving as useful as I'd imagined and had introduced various maintenance difficulties. In this release the APIs are deprecated and do nothing. Logging will be removed altogether in version 2.0.

Also for .NET developers

icon MimeTypes.NET: MIME type constants for your .NET projects

RegexToolbox for other languages

icon RegexToolbox for Java

icon RegexToolbox for Kotlin

icon RegexToolbox for JavaScript


RegexToolbox: Now you can be a hero without knowing regular expressions.

regextoolbox.net's People

Contributors

markwhitaker avatar dependabot[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.