All Projects → tiehuis → zig-regex

tiehuis / zig-regex

Licence: MIT License
A regex implementation for the zig programming language

Programming Languages

Zig
133 projects
c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to zig-regex

Regex
An implementation of regular expressions for Rust. This implementation uses finite automata and guarantees linear time matching on all inputs.
Stars: ✭ 2,125 (+3441.67%)
Mutual labels:  regex, regex-engine
moar
Deterministic Regular Expressions with Backreferences
Stars: ✭ 19 (-68.33%)
Mutual labels:  regex, regex-engine
assemblyscript-regex
A regex engine for AssemblyScript
Stars: ✭ 81 (+35%)
Mutual labels:  regex, regex-engine
log4stash
Module to Log log4net Messages to ElasticSearch
Stars: ✭ 60 (+0%)
Mutual labels:  regex
rust-regex-playground
Web tool to evaluate rust regular expressions
Stars: ✭ 13 (-78.33%)
Mutual labels:  regex
rewrite-imports
Rewrite `import` statements as `require()`s; via RegExp
Stars: ✭ 31 (-48.33%)
Mutual labels:  regex
subst
Search and des... argh... replace in many files at once. Use regexp and power of Python to replace what you want.
Stars: ✭ 20 (-66.67%)
Mutual labels:  regex
learn js regexp
Example based guide to mastering JavaScript regexp
Stars: ✭ 85 (+41.67%)
Mutual labels:  regex
extglob
Extended globs. Add (almost) the expressive power of regular expressions to glob patterns.
Stars: ✭ 25 (-58.33%)
Mutual labels:  regex
genex
Genex package for Go
Stars: ✭ 64 (+6.67%)
Mutual labels:  regex
String.prototype.matchAll
Spec-compliant polyfill for String.prototype.matchAll, in ES2020
Stars: ✭ 14 (-76.67%)
Mutual labels:  regex
crystular
Crystal regex tester http://www.crystular.org/
Stars: ✭ 31 (-48.33%)
Mutual labels:  regex
mention-hashtag
Extract mentions (@mention) or hashtags (#hashtag) from any text
Stars: ✭ 16 (-73.33%)
Mutual labels:  regex
regex-cache
Memoize the results of a call to the RegExp constructor, avoiding repetitious runtime compilation of the same string and options, resulting in dramatic speed improvements.
Stars: ✭ 39 (-35%)
Mutual labels:  regex
rustexp
A Rust regular expression editor and tester that runs entirely within the browser!
Stars: ✭ 59 (-1.67%)
Mutual labels:  regex
i3blocks-modules
Custom modules for i3blocks status bar
Stars: ✭ 36 (-40%)
Mutual labels:  regex
datagoose
🔐 Easy to use, fast, lightweight, secure, JSON based database for Python!
Stars: ✭ 13 (-78.33%)
Mutual labels:  regex
hex-color-regex
Regular expression for matching hex color values from string.
Stars: ✭ 29 (-51.67%)
Mutual labels:  regex
regex
A set of ready-made regex helper methods for use in your Laravel application.
Stars: ✭ 226 (+276.67%)
Mutual labels:  regex
extract-email-address
Extracts email address from an arbitrary text input.
Stars: ✭ 45 (-25%)
Mutual labels:  regex

An automaton-based regex implementation for zig.

Note: This is still a work in progress and many things still need to be done.

  • Capture group support
  • UTF-8 support
  • More tests (plus some automated tests/fuzzing)
  • Add a PikeVM implementation
  • Literal optimizations and just general performance improvements.

Usage

const debug = @import("std").debug;
const Regex = @import("regex.zig").Regex;

test "example" {
    var re = try Regex.compile(debug.global_allocator, "\\w+");

    debug.assert(try re.match("hej") == true);
}

Api

Regex

fn compile(a: &Allocator, re: []const u8) !Regex

Compiles a regex string, returning any errors during parsing/compiling.


pub fn match(re: &const Regex, input: []const u8) !bool

Match a compiled regex against some input. The input must be matched in its entirety and from the first index.


pub fn partialMatch(re: &const Regex, input: []const u8) !bool

Match a compiled regex against some input. Unlike match, this matches the leftmost and does not have to be anchored to the start of input.


pub fn captures(re: &const Regex, input: []const u8) !?Captures

Match a compiled regex against some input. Returns a list of all matching slices in the regex with the first (0-index) being the entire regex.

If no match was found, null is returned.

Captures

pub fn sliceAt(captures: &const Captures, n: usize) ?[]const u8

Return the sub-slice for the numbered capture group. 0 refers to the entire match.

pub fn boundsAt(captures: &const Captures, n: usize) ?Span

Return the lower and upper byte positions for the specified capture group.

We can retrieve the sub-slice using this function:

const span = caps.boundsAt(0)
debug.assert(mem.eql(u8, caps.sliceAt(0), input[span.lower..span.upper]));

References

See the following useful sources:

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].