Giter VIP home page Giter VIP logo

regulex's Introduction

Regulex

Regulex is a JavaScript Regular Expression Parser & Visualizer.

Try it now: https://jex.im/regulex/

This project is under reconstruction!

Features

  • Written in pure JavaScript. No backend required.
  • You can embed the graph on you own site through HTML iframe element.
  • Detailed error message. In most cases it can point out the precise syntax error position.
  • No support for octal escape. Yes it is a feature! ECMAScript strict mode doesn't allow octal escape in string, but many browsers still allow octal escape in regex. In regulex, DecimalEscape will always be treated as back reference. If the back reference is invalid, e.g. /\1/, /(\1)/, /(a)\2/, or DecimalEscape appears in charset(because in this case it can't be explained as back reference, e.g. /(ab)[\1]/, Regulex will always throw an error.

Install for Node.js

npm install regulex

Local Build for Browser

This command will generate bundle dist/regulex.js for browser side:

git checkout legacy
npm install -g requirejs
r.js -o build-config.js

API

Parse to AST

var parse = require("regulex").parse;
var re = /var\s+([a-zA-Z_]\w*);/ ;
console.log(parse(re.source));

Visualize

var parse = require("regulex").parse;
var visualize = require("regulex").visualize;
var Raphael = require('regulex').Raphael;
var re = /var\s+([a-zA-Z_]\w*);/;
var paper = Raphael("yourSvgContainerId", 0, 0);
try {
  visualize(parse(re.source), getRegexFlags(re), paper);
} catch(e) {
  if (e instanceof parse.RegexSyntaxError) {
    logError(re, e);
  } else {
    throw e;
  }
}

function logError(re, err) {
  var msg = ["Error:" + err.message, ""];
  if (typeof err.lastIndex === "number") {
    msg.push(re);
    msg.push(new Array(err.lastIndex).join("-") + "^");
  }
  console.log(msg.join("\n"));
}


function getRegexFlags(re) {
  var flags = "";
  flags += re.ignoreCase ? "i" : "";
  flags += re.global ? "g" : "";
  flags += re.multiline ? "m" : "";
  return flags;
}

regulex's People

Contributors

cjex avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

regulex's Issues

Please publish to npm

Tried installing via npm i regulex but apparently this package is not published to the registry. When examples mention require('regulex'), it kind of confuses when package is not found and you need to clone and build it manually.

vue下面怎么使用

vue.runtime.esm.js?2b0e:619 [Vue warn]: Error in callback for watcher "formInfo.reg_param": "Error: define cannot be used indirect"
Vue下面会报出如上错误,怎么使用

Null character not being considered

From the documentation for the JavaScript regular expressions there is a null representation with the \0 character however, the parser recognises this as a 0 which is not correct.

Any chance of solving this?

Named capture groups ?

Hey, nice tool, I might use that to help others understand regexp better ;)

However, it seems your script doesn't handle named capture groups :
Python's (?P<name1>xxx) to be refered as (?P=name1)
or Perl's (?<name1>) => \k<name1>

Might be fun to add to your parser...

I can't export image

I write a regular expression,I would download the corresponding visual image, but I can't do it.
Error:
Mixed Content: The page at 'https://jex.im/regulex/#!embed=false&flags=&re=%5E%23-%3F%5B1-9%5D%2B%5B0-9%5D*%3A-%3F(%5B0-9%5D%7C%5B1-9%5D%2B%5B0-9%5D*)%24' was loaded over HTTPS, but requested an insecure script 'http://libs.useso.com/js/require.js/2.1.11/require.min.js'. This request has been blocked; the content must be served over HTTPS.

require.min.js download failed

Adding option to collapse the AST

Regulex works perfect for Regex not long enough, you can easily visualize the generated .svg against the expression. However, when it comes to fairly LARGE REGEXes, it becomes really hard to drag/scroll the webpage. Is there any way to integrate a collapsible option to collapse the regions of the AST if possible?

Repetition off by 1

The regex: color: #[0-9A-F]{6};

Erroneous:
grafik

Should be:
grafik

The path goes through the letters at least once, so we can do that only 5 times more, not 6 times.

real time

the visualisation should be in real time zhen typing

Add support for regex paste

A little nice feature would be to detect when the user paste something in the input field and if it looks like a regex, automagically remove the regex delimiter, and extract optional flags.

To understand what I mean, try to paste this whole regex /^https?:\/\//ig into regex101 website https://regex101.com/.

Also, when a regex is pasted, it should automatically update the image.

What do you think ?

unexpected char on pipe symbol

Was presented with an unexpected char error when trying to make your awesome tool choke on this regexp pattern which I myself am not responsible for having written but nonetheless does still validly work (as a java.util.regex pattern):

(\w*?)(\s+|^)(NORTHEAST |NORTHWEST |SOUTHEAST |SOUTHWEST |NORTH |SOUTH |EAST |WEST |NE |NW |SE |SW |N |E |S |W |)\s*?((COUNTY |CNTY |CTY |STATE |ST |US |UNITED STATES |TOWNSHIP |TS |TWP |OLD |RANCH |INTERSTATE |)\s*?((?<=(?:COUNTY |STATE |ST |RANCH |CNTY |CTY |TOWNSHIP |TS |TWP |OLD |))ROAD|(?<=(?:COUNTY |STATE |ST |RANCH |CNTY |CTY |TOWNSHIP |TS |TWP |OLD ))RD|(?<= )HIGHWAY|(?<= )HIWAY|(?<= )HWY|(?<= )EXPRESSWAY|(?<!^STAR |^TRACY|^)ROUTE|(?<!(?:^STAR |^TRACY|^))RTE|rte|(?<!(?:^STAR |^TRACY|^))RT(?= )|(?<= )CR(?= )|(?<= )VIA(?= )|(?<= )INTERSTATE(?= )|(?<= )LOOP|(?<= )I(?=-\d+)|(?<= )I(?= \d+)|(?<= )I(?=\d+)))($|[-\s]*(\w?\w*)( NORTHEAST(?=$| )| NORTHWEST(?=$| )| SOUTHEAST(?=$| )| SOUTHWEST(?=$| )| NORTH(?=$| )| SOUTH(?=$| )| EAST(?=$| )| WEST(?=$| )| NE(?=$| )| NW(?=$| )| SE(?=$| )| SW(?=$| )| N(?=$| )| E(?=$| )| S(?=$| )| W(?=$| )|)\s*(.*?))

Error on matching backslash

If I want to match a backslash in a string,I use str.match(/\\/) but the Visualizer parses it incorrectly.

233209

Support Named Capture Groups

It would be great if you could support named capture groups e.g. (?.*)

Even if initially you just did a search replace removing them, it would make it much easier to copy and paste a regex in to visualize as I just manually removed 10 from a regex I copied in to check out your tool.

Long term, it would be great to add them to the visualization as a label, but I can respect that its more work and I'm asking for something without giving anything back.

Improve error message for repeat after group or assertion case.

Give a tip for ([a-z]){3},Repeat after capture group, only the last appearance will be captured. For example: /([a-z]){3}/.exec("abc") will result ["abc","c"]

/a(?=bc){3}//a(?=bc)+/ should warn "They are the same as /a(?=bc)/"
/a(?=bc)*//a(?=bc){0,3}//a(?=bc)?/ should warn "They are the same as /a/ "

Group counting issue

Hey, Thanks for writing this visualiser, I enjoyed playing with it 👍

However I noticed an issue where nested capture groups cause backrefs to be marked as recursive when they aren't.

screen shot 2014-11-26 at 13 13 57

In the screenshot, the diagram shows the outer capture group as \1 and the inner group as \2. This is consistent with grep. However when I add \2 inside group 1, but not inside group 2, the backref is marked as recursive.

Support negative look behind

Thank you very much for this excellent tool!
I love using it, it really helps

I saw I can't use the negative look behind syntax ?<!
Can you please add support for that?

Example -
find all strings 'py' that are not prefixed by 'co'
/(?<!co)py/

Thanks

Display picture bug  

I want to match text like this: it can only contain lowercase letters, numbers, English. and underscores. the Regular expression is:/^[a-z_\d.]+$/ but something wrong with the displayed image
image.png

Youtube extractor prb

Hi linpolly .
I got problems to download ing video and getting error . Remember ? Last
Time you have fixed and said me once it update again you will help .

Can i know how i can fix to download latest youtube video.

And you remember last time you have fixed?

Support XRegExp extended syntax

XRegExp augments JavaScript regex syntax with additional features like named capture, the x flag for free spacing and line comments, and \p{..} for Unicode properties. It would be awesome if Regulex supported these features as well. Apart from XRegExp, they're supported in a variety other modern regex implementations (Java, Perl, PCRE, .NET, etc.).

Naming Capture groups

Support for naming capture groups would be nice.

i.e. / (?<Date>\d{4}-\d{2}-\d{2}) /
could be displayed as Group #1: Date

Error in Internet Explorer

pattern using character ranges in square brackets when using Internet Explorer causes "unterminated character class" error. Same pattern does not error in Chrome. [0-4]

regulex-ie-error

support matched expressions

excellent tool btw -

it would be nice to have it on par with something like rubular.com for matching multiple patterns

screen shot 2015-02-03 at 2 34 02 am

window is not defined

您好:
我直接执行 node test.js
代码:
var parse = require('regulex').parse;
var re = /var\s+([a-zA-Z_]\w*);/ ;
console.log(parse(re.source));
但是报错 window is not defined,请问这个程序只能通过浏览器使用么?

报错详情:
/home/song/Desktop/regulex-master/dest/regulex.js:63
var r=[l()],n=t.num;return{accepts:r,trans:[{from:e,to:r,charset:!1,assert:function(t,e,r,i,a){var s=u(t,n,a);return void 0===s&&(s=""),a.slice(r,r+s.length)===s&&s.length}}]}}function o(t,e){var r=[],n=[];return t.branches.forEach(function(t){var i=c(t,e);r=r.concat(i.trans),n=n.concat(i.accepts)}),{trans:r,accepts:n}}function h(t,e){function n(t,e,r){var n=[l()];return{accepts:n,trans:[{from:e,to:n,charset:!1,assert:r}]}}function i(t){var e=r(c(t.sub,["start"]));return function(t,r,n,i,a){var s=e.input(a,n,null,t);return s.acceptable}}function a(t){var e=i(t);return function(){return!e.apply(this,arguments)}}function s(t,e){return!!(o(t-1,e)^o(t,e))}function o(t,e){return t!==-1&&t!==e.length&&/\w/.test(e[t])}function h(t,e,r,n,i){return 0===r||"\n"===i[r-1]}function u(t,e,r,n,i){return 0===r}function f(t,e,r,n,i){return r===i.length||"\n"===e}function p(t,e,r,n,i){return r===i.length}var d;switch(t.assertionType){case AssertBegin:d=t.multiline?h:u;brea

ReferenceError: window is not defined
at Object. (/home/song/Desktop/regulex-master/dest/regulex.js:63:14889)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object. (/home/song/Desktop/regulex-master/dest/test.js:1:95)
at Module._compile (module.js:570:32)

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.