GithubHelp home page GithubHelp logo

luckasranarison / regex-potata Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 273 KB

Potata regex engine

Home Page: https://luckasranarison.github.io/regex-potata/

License: MIT License

Rust 70.46% JavaScript 1.46% HTML 1.30% TypeScript 26.16% CSS 0.61%
automata-theory nfa regex-engine thompson-construction

regex-potata's Introduction

Regex-potata

A basic regex engine, built as a practical application of automata theory, implements an E-NFA using Thompson construction and BFS for NFA simulation.

Usage

use regex_potata::Regex;

fn main() {
    let re = Regex::new("hello (w|w)orld!*").unwrap();
    let result = re.test("hello world!!!");

    println!("{}", result); // true

    let re = Regex::new(r#"(?<day>\d{2})-(?<month>\d{2})-(?<year>\d{4})"#).unwrap();
    let captures = re.captures("07-01-2024").unwrap();

    println!("{:?}", captures.get_name("day"));
    println!("{:?}", captures.get_name("month"));
    println!("{:?}", captures.get_name("year"));

    let re = Regex::new("(T|t)h(e|(e|o)se)").unwrap();
    let matches = re.find_all("the These those The");

    println!("{:?}", matches);
}

TODOs

  • Basic regex foo (bar) | .
  • Quantifiers + ? * {x} {x,y} {x,}
  • Character classes [a-z] [^x] \d \D \w \W \s \S
  • Captures (foo) (:?bar) (?<named>foo)
  • Anchors ^ $
  • NFA visualizer

regex-potata's People

Contributors

luckasranarison avatar

Stargazers

 avatar

Watchers

 avatar  avatar

regex-potata's Issues

Quantified capture groups

When quantifiers are applied to expressions inside parentheses, the last match should be the captured one. Like in the following:

const re = /(hi)+(ha)+/;
const input = "hihiha";
console log(input.match(re));
// [ 'hihiha', 'hi', 'ha', index: 0, input: 'hihiha', groups: undefined ]

The matched hi is the last one, i.e the second one. But it doesn't work in the current implementation.

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.