Giter Site home page Giter Site logo

ctregex.zig's Introduction

Zig compile time regular expressions

Generating fast code since 2020

Features

  • Comptime regular expression compilation
  • Comptime and runtime matching
  • UTF8, UTF16le, ASCII, codepoint array support
  • Captures (with named (:<name>...) support)
  • |, *, +, ?, (:?...), [...], [^...], {N}, {min,}, {min,max}
  • '\d', '\s' character classes

TODO

  • Faster generated code using DFAs when possible
  • search, findAll, etc.
  • More character classes
  • More features (backreferences etc.)

Example

test "runtime matching" {
    @setEvalBranchQuota(1250);
    // The encoding is utf8 by default, you can use .ascii, .utf16le, .codepoint here instead.
    if (try match("(?<test>def|abc)([๐Ÿ˜‡ฯ‰])+", .{.encoding = .utf8}, "abc๐Ÿ˜‡ฯ‰ฯ‰ฯ‰ฯ‰ฯ‰")) |res| {
        std.debug.warn("Test: {}, 1: {}\n", .{ res.capture("test"), res.captures[1] });
    }
}

test "comptime matching" {
    @setEvalBranchQuota(2700);
    if (comptime try match("(?<test>def|abc)([๐Ÿ˜‡ฯ‰])+", .{}, "abc๐Ÿ˜‡ฯ‰ฯ‰ฯ‰ฯ‰ฯ‰")) |res| {
        @compileError("Test: " ++ res.capture("test").? ++ ", 1: " ++ res.captures[1].?);
    }
}

See tests.zig for more examples.
Small benchmark with ctregex, PCRE2

ctregex.zig's People

Contributors

alexnask avatar katesuyu avatar

Watchers

 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.