Code Monkey home page Code Monkey logo

rgx's Introduction

rgx

A very simple regex engine written in go. This library is experimental, use it at your own risk!

read the article.

to add the dependency:

go get github.com/rhaeguard/rgx

how to use:

import "github.com/rhaeguard/rgx"

pattern, err := rgx.Compile(regexString)
if err != nil {
	// error handling
}
results := pattern.FindMatches(content)

if results.Matches {
	groupMatchString := results.Groups["group-name"]
}

todo

  • ^ beginning of the string
  • $ end of the string
  • . any single character/wildcard
  • bracket notation
    • [ ] bracket notation/ranges
    • [^ ] bracket negation notation
    • better handling of the bracket expressions: e.g., [ab-exy12]
    • special characters in the bracket
      • support escape character
  • quantifiers
    • * none or more times
    • + one or more times
    • ? optional
    • {m,n} more than or equal to m and less than equal to n times
  • capturing group
    • ( ) capturing group or subexpression
    • \n backreference, e.g, (dog)\1 where n is in [0, 9]
    • \k<name> named backreference, e.g, (?<animal>dog)\k<animal>
    • extracting the string that matches with the regex
  • \ escape character
    • support special characters - context dependant
  • better error handling in the API
  • ability to work on multi-line strings (tested on Alice in Wonderland text corpus)
    • . should not match the newline - \n
    • $ should match the newline - \n
    • multiple full matches

notes

  • \ escape turns any next character into a literal, no special combinations such as \d for digits, \b for backspace, etc. are allowed
  • numeric groups \n only support single digit references, so \10 will be interpreted as the first capture group followed by a literal 0

credits

rgx's People

Contributors

rhaeguard avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

ktelyakov

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.