Live data from Hacker News

Regexper – Regular expressions visualizer

regexper.com

51–60 of 108 posts

Re: Regexper – Regular expressions visualizer

#51
Back when https://xkcd.com/1930/ was posted, I made a regular expression to create a generator using a regex sampler (for instance http://dwickern.github.io/regex-sample/ ).

I've put the regex at https://gist.github.com/kmill/17c5ef4f99bd9ef7ad799f0b487448...

The amusing thing to me is that this regex visualizer can reproduce the comic.

Re: Regexper – Regular expressions visualizer

#52
I would think it would be better to minimize the pseudo dfa to collapse states.

Also having each character of an alternation of subset in light blue box then laying them out vertically makes the hard to read.

Of the point of this is to make regex more easily understood, you would think you would want to make them compact.

Re: Regexper – Regular expressions visualizer

#53
post #5

Nice. From this SO answer: https://stackoverflow.com/a/800847/415384 we get this: https://regexper.com/#%5E(%3F%3A(%3F%3A(%3F%3A0%3F%5B13578%5... or from another answer: https://regexper.com/#((1%7C0(00)*01)((11%7C10(00)*01))*%7C(... )

Thad first one doesn't seem very good. It seems like there are many places states could be merged. Eg, there are 4 different "^0" states and 3 "^1" states. or am i misreading something?

Amazing how being able to visualize the problem reveals available optimizations!

Re: Regexper – Regular expressions visualizer

#55
post #49
post #41

Earlier quoted context omitted.

The visualization tool shows that the regex is not correct. It allows 000.000.000.000 as an IPv4 address

I created this instead: https://regexper.com/#((%5B0-9%5D%5C.)%7C(%5B1-9%5D%5B0-9%5D... The repetition count seems to be displayed off-by-one though.

On mobile so can't (easily) test it, but doesn't this produce a false negative for `246.{snip}`, for example?

Re: Regexper – Regular expressions visualizer

#56
post #45
post #37

After 20 years of software development I‘ve come to adopt a best practise: Whenever I start writing a regular expression, I stop and write a „manual“ domain specific parse function instead. Saved me a LOT of debugging time. Since I can now use kotlin pretty much anywhere (jvm, browser, shellscripts) this is easy because of the superb stdlib („startsWith“, „lastIndexOf“, „substringBeforeLast(...)“) The time saved I in…

I can't shake the feeling that Regexp could be written just as efficiently as a fluent interface with a more human friendly syntax. I've been telling Jr devs bucking for promotion for years to explain what they're doing in plain english, then write code that looks like that. Basically telling them to skip right over the "gee look what a clever fuck I am" stage and write good code instead of creating riddles. The Rege…

Parsing combinators are the API you want.

    regexReplaced n = do
       char 'T'
       spaces
       x 
The above is a Haskell function that does the parsing required above, returning the alphanumeric characters if the parse succeeds and returning an error if it does not. You may not speak Haskell, but this is probably still more readable than (n) => {new RegExp(`T\s(\w{${n}}\w)\s*=`)}, which is the Javascript function that does a similar thing.

Re: Regexper – Regular expressions visualizer

#57
post #27

Earlier quoted context omitted.

Wow, that is really cool. I actually started typing in random characters and tracing the matches through the graph for the Regex from StackOverflow mentioned earlier. I didn't know what the regex matches, so I played it like a game , trying to reach the finish by typing one character at a time. When I finished, I saw that I had typed "01/31/1691" and then realised that it's a regex for dates.

Sounds like you'd love https://regexcrossword.com/

+1 for regex crossword. That's a lot of fun.

Re: Regexper – Regular expressions visualizer

#58
post #2

Neat! I also suggest: https://regexr.com/

emacs also has a visual regexp builder mode (M-x re-builder) that shows the 200 first matches in the current buffer to validate that the regular expression does what you want. But AFAIR there are syntax differences between different regexp flavors and emacs uses the elisp flavor of course.

Re: Regexper – Regular expressions visualizer

#59
post #45
post #37

After 20 years of software development I‘ve come to adopt a best practise: Whenever I start writing a regular expression, I stop and write a „manual“ domain specific parse function instead. Saved me a LOT of debugging time. Since I can now use kotlin pretty much anywhere (jvm, browser, shellscripts) this is easy because of the superb stdlib („startsWith“, „lastIndexOf“, „substringBeforeLast(...)“) The time saved I in…

I can't shake the feeling that Regexp could be written just as efficiently as a fluent interface with a more human friendly syntax. I've been telling Jr devs bucking for promotion for years to explain what they're doing in plain english, then write code that looks like that. Basically telling them to skip right over the "gee look what a clever fuck I am" stage and write good code instead of creating riddles. The Rege…

> "I can't shake the feeling that Regexp could be written just as efficiently as a fluent interface with a more human friendly syntax."

You may be interested in the Parse dialect of Red:

http://www.red-lang.org/2013/11/041-introducing-parse.html

Also worth noting that Red can be embedded in any program that supports a C function interface, through using LibRed.

http://www.red-lang.org/2017/03/062-libred-and-macros.html?m...

Re: Regexper – Regular expressions visualizer

#60
post #40

It's always neat to see where one's ideas go! AFAIK, I was the first person to create dynamic railroad diagrams for regular expressions (maybe 12 or 13 years ago). I got the idea from json.org, which I think was Douglas Crockford's brainchild. My initial implementation was strfriend.com (in Lisp: well under 1,000 lines, including views), and I think its main claim to fame was that Jeff Atwood made fun of it on Twitte…

I was taught the algorithms to do this stuff in my Computer Science class over 20 years ago (RE is equivalent to DFA). You weren't the first person to implement regular expression visualizations.
Post reply on HN