Giter Club home page Giter Club logo

jager's Introduction

jager

I would recommend re-implementing this if you plan on using it for anything yourself. The approach in this library is a poorly-informed implementation based on parser actions.

If anyone is curious on how something like this would be implemented correctly I would recommend reading Russ Cox's series of posts, and convert a regular expression into a proper DFA as described here. Then this library reduces to traversing the DFA randomly until reaching an accept state.

GitHub release

This is a project built with marpa.

Given a regular expression, generate a string that matches that expression

Installation

Add this to your application's shard.yml:

dependencies:
  jager:
    github: omarroth/jager

Usage

require "jager"

regex = /\d{3}-\d{3}-\d{4}/
engine = Jager::Engine.new

input = engine.generate(regex)

input # => "754-327-6740"

Examples

Name Regex Output
US Phone /\d{3}-\d{3}-\d{4}/ "019-586-1821"
UUID /[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}/ "0d007d29-f50b-4763-f40e-102fcaa77a1b"
JSON Number /-?[1-9]\d+(.\d+)?([eE][+-]?\d+)?/ "85.2292e+6745508109"
US Dollar /\$([1-9]{1}[0-9]{0,2})(,\d{3}){0,4}(.\d{2})?/ "$7,239,557,686.39"

Notes

  • Jager does not support:
    • anchors ($, ^),
    • extended character classes ([[:digit:]], [[:alpha:]])

Contributing

  1. Fork it ( https://github.com/omarroth/jager/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

  • omarroth Omar Roth - creator, maintainer

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.