Live data from Hacker News

Regexper – Regular expressions visualizer

regexper.com

81–90 of 108 posts

Re: Regexper – Regular expressions visualizer

#81
post #2

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

I used regexr quite a lot during my daily work. I think regexper more suited for complex structures whereas regexr is better for checking the meaning of simple expressions because of the hover-over function.

Agreed. I use regexr daily for building my regex's without having to execute the programs they'll be part of.

Re: Regexper – Regular expressions visualizer

#82
post #49

Earlier quoted context omitted.

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?

Yes, you are right...the following better? https://regexper.com/#((%5B0-9%5D%5C.)%7C(%5B1-9%5D%5B0-9%5D...

Re: Regexper – Regular expressions visualizer

#83
post #66
post #49

Earlier quoted context omitted.

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.

Does not match: 10.1 -> 10.0.0.1

In IPv4 addresses, as far as I know, this is not done -- it is only IPv6 addresses that use the double colon to indicate a sequence of zeros.

Re: Regexper – Regular expressions visualizer

#84
I'm an rx geek and can often craft what I'm looking to get without a lot of help, but I have used this tool many times before -- it's very slick. It would be nice if it supported something other than JavaScript[0], but hey, it's on the web, it probably makes a lot of sense to be that way (and it's nice that it's all client-side and I don't have to wait for it to ship my regular expression back to a server for processing).

Regular expressions are simply awesome and I'm continually surprised at how frequently I run into developers who have next-to-no understanding of them.Case in point, I ran into some code a few months ago that spanned two methods and 20-lines to do something that a 6-character regular expression could have solved (and would have done so more performantly[1]); the best part was that part of what I was responsible for handling was a bug that ended up residing right inside one of those methods. And then there's all of the things related to "dealing with strings" that many regular expression libraries just handle, such as "\d" vs "[0-9]" in a world with unicode strings[3]. It feels cryptic[4] when you encounter it and you're not familiar with the syntax, but to learn the "80% most useful parts", you needn't study much more than content that would fit on a single printed sheet of paper (and to get the last 20%, you'd need, maybe 2, ... 3?)

All of that said, there's also the other side of the coin; if ever the saying "If all you have is a hammer, everything looks like a nail" had application, it's with regular expressions. I'm not sure how many times the question "How do I write a regular expression to parse HTML" has to be responded with "don't" before folks quit trying[2]. It tends to be the first thing I reach for when I have a need to process text, even when there are better tools; heck, all of my find/replace dialogues in every application that supports it have the "Regex" box checked by default (and it really throws me off when I hit up "Find" in the browser and need to search for something with a ( or ) in it which I escape due to muscle memory)

[0] I have an occasional need for PCRE and .NET style; and I really miss named-groups when I have to do something complex in JavaScript.

[1] While it's easy to accidentally end up in hell, ala https://blog.codinghorror.com/regex-performance/, poorly written string-search code can be worse when the complexity of the pattern your searching for reaches a certain point, and that's to say nothing of the errors per x lines of code and readability (not that rx is particularly readable under complexity).

[2] And hey, I've got a shell script that downloads a few status pages on my server at home that uses awk with regular expressions to extract values from a web page. I wouldn't say it necessarily qualifies as "parsing HTML" since it's really only concerned with looking for a small string which it filters a second time to get the value -- horribly inefficient, but it's worked for 5 years through page changes without requiring adjustment.

[3] At least in the C# world, are about twice as slow due to handling digits "correctly" https://stackoverflow.com/questions/16621738/d-is-less-effic...

[4] While it's usually written cryptically, many (most?) implementations support flags to ignore whitespace and support comment features. I've had a few crazy-ugly rx's that I had to use to extract data from a ticketing system's "blob field" to insert into a structured format; were it not for that feature, it would have been impossible to write and support.

Re: Regexper – Regular expressions visualizer

#85
post #45

Earlier quoted context omitted.

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 can use SRL - Simple Regex Language ( https://simple-regex.com/ ) for making readable regex/matching rules. It is supported in C++, Java, C#, PHP, Javascript, and Python. Also, you can use the web version to generate equivalent regex if your language is one of the above. Here is an…

Interesting, thanks for mentioning! Looks similar to VerbalExpressions (https://github.com/VerbalExpressions/JSVerbalExpressions/wik...)

Re: Regexper – Regular expressions visualizer

#87
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…

Strfriend was very good, it helped me learn regex in a big way. Thanks!

Re: Regexper – Regular expressions visualizer

#88
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.

I studied computer science, too. DFA graphs are not the same as railroad diagrams.

Re: Regexper – Regular expressions visualizer

#89
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…

Railroad diagrams for regular expressions were common long before 2005, and generating such images on demand isn't that unusual, so your work is unlikely to have been a major influence here. Similarly, automatically translating regular expressions from one engine to another is something that people have done before (out of necessity, for compatibility).

Do you have an example? I love reading original sources. I'd never seen a regex as a railroad diagram before that, though I admit it's entirely possibly I'd seen it somewhere and forgotten.

I don't know of any software that translates regular expressions, either, though I'm sure I can't be the first.

Re: Regexper – Regular expressions visualizer

#90
post #89

Earlier quoted context omitted.

Railroad diagrams for regular expressions were common long before 2005, and generating such images on demand isn't that unusual, so your work is unlikely to have been a major influence here. Similarly, automatically translating regular expressions from one engine to another is something that people have done before (out of necessity, for compatibility).

Do you have an example? I love reading original sources. I'd never seen a regex as a railroad diagram before that, though I admit it's entirely possibly I'd seen it somewhere and forgotten. I don't know of any software that translates regular expressions, either, though I'm sure I can't be the first.

This fairly common piece of software does it.

https://www.regexbuddy.com

4th result on google for "regex conversion" for me. Seems like there are quite a few others.

Post reply on HN