All Projects → hokein → Automata.js

hokein / Automata.js

A regular expression converter

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Automata.js

Js Regular Expression Awesome
📄我收藏的正则表达式大全,欢迎补充
Stars: ✭ 120 (-40.59%)
Mutual labels:  regular-expression
Srl Php
Simple Regex Language
Stars: ✭ 1,808 (+795.05%)
Mutual labels:  regular-expression
Regex.persian.language
Collection of Regex for validating, filtering, sanitizing and finding Persian strings
Stars: ✭ 172 (-14.85%)
Mutual labels:  regular-expression
Randexp.js
Create random strings that match a given regular expression.
Stars: ✭ 1,682 (+732.67%)
Mutual labels:  regular-expression
Regex Dos
👮 👊 RegEx Denial of Service (ReDos) Scanner
Stars: ✭ 143 (-29.21%)
Mutual labels:  regular-expression
Router
⚡️ A lightning fast HTTP router
Stars: ✭ 158 (-21.78%)
Mutual labels:  regular-expression
Regular
🔍The convenient paste of regular expression🔎
Stars: ✭ 118 (-41.58%)
Mutual labels:  regular-expression
Xo
Command line utility that composes regular expression matches.
Stars: ✭ 184 (-8.91%)
Mutual labels:  regular-expression
Compile Time Regular Expressions
A Compile time PCRE (almost) compatible regular expression matcher.
Stars: ✭ 2,144 (+961.39%)
Mutual labels:  regular-expression
Regularexpressiondecoder
A decoder that constructs objects from regular expression matches.
Stars: ✭ 169 (-16.34%)
Mutual labels:  regular-expression
Braces
Faster brace expansion for node.js. Besides being faster, braces is not subject to DoS attacks like minimatch, is more accurate, and has more complete support for Bash 4.3.
Stars: ✭ 133 (-34.16%)
Mutual labels:  regular-expression
Micromatch
Contributing Pull requests and stars are always welcome. For bugs and feature requests, please create an issue. Please read the contributing guide for advice on opening issues, pull requests, and coding standards.
Stars: ✭ 1,979 (+879.7%)
Mutual labels:  regular-expression
Grex
A command-line tool and library for generating regular expressions from user-provided test cases
Stars: ✭ 4,847 (+2299.5%)
Mutual labels:  regular-expression
Dan Jurafsky Chris Manning Nlp
My solution to the Natural Language Processing course made by Dan Jurafsky, Chris Manning in Winter 2012.
Stars: ✭ 124 (-38.61%)
Mutual labels:  regular-expression
Ocaml Re
Pure OCaml regular expressions, with support for Perl and POSIX-style strings
Stars: ✭ 172 (-14.85%)
Mutual labels:  regular-expression
Tokenizer
Source code tokenizer
Stars: ✭ 119 (-41.09%)
Mutual labels:  regular-expression
Find
A find-in-page extension for Chrome and Firefox that supports regular expressions.
Stars: ✭ 157 (-22.28%)
Mutual labels:  regular-expression
Regexpu
A source code transpiler that enables the use of ES2015 Unicode regular expressions in ES5.
Stars: ✭ 201 (-0.5%)
Mutual labels:  regular-expression
Web Database Analytics
Web scrapping and related analytics using Python tools
Stars: ✭ 175 (-13.37%)
Mutual labels:  regular-expression
Parseback
A Scala implementation of parsing with derivatives
Stars: ✭ 168 (-16.83%)
Mutual labels:  regular-expression

Automata.js

Automata.js is a regular expression converter written in JS for both Node.js and browser.

It aims to convert regular expression to finite state machine(FSM, like NFA). Besides, dot script transition is provided so that you can make diagrams with Graphiz.

Try it online!

screenshot

Development

// Install dependency modules.
npm install

// Run test.
make test

// Generate browser js.
make distribution

API Description

Currently, Automata.js supports minimal regular expressions:

  • +: One or more
  • *: Zero or more
  • ?: Zero or one
  • (): Capture everything enclosed
  • |: Or
  • \n: Newline
  • \r: Carriage return
  • \t: Tab
  • \w: [a-zA-Z0-9_]
  • \d: [0-9]

FSM

FSM is a object represent a finite state machine(NFA, DFA).

The json definition is below:

{
  initialState: 'id',
  acceptState: ['id', ... ] ,
  numOfStates: Integer,
  type: 'DFA' or 'NFA',
  transitions: {
    'id': { 'to_id': label, },
    ...,
  }
}

FSM.toDotScript()

Convert the fsm to Graphiz dot script.

FSM.match(text)

  • text: String

Determine whether text matches to the FSM. This methods only supports DFA.

RegParser

RegParser is a regular expression parser.

RegParser.reset(string)

Set regular expression string in parser.

RegParser.parseToNFA()

Parses the given regular expression.

Returns a FSM object, the FSM represents a Nondeterministic Finite Automata(NFA).

RegParser.parseToDFA()

Parses the given regular expression.

Returns a FSM object, the FSM represents a Deterministic Finite Automata(DFA).

Usage

Usage in Node.js

Install via npm install automata.js.

var regParser = require('automata.js');

var parser = new regParser.RegParser('a*b');
var nfa = parser.parseToNFA();

console.log(nfa.toDotScript());

Usage in Browser

Automata.js uses node-browserify to generate a browser distribution.

You can use Viz.js to render graphiz dot script in your web page.

var regParser = require('automata.js');

var parser = new regParser.RegParser('a*b');
var nfa = regParser.parseToNFA();

// render dot script to svg.
var result = Viz(nfa.toDotScript(), 'svg', 'dot');
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].