Earlier quoted context omitted.
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 simila…
But are they as efficient as regexp? I personally prefer regexp combinators.
Regexper – Regular expressions visualizer
91–100 of 108 posts
Re: Regexper – Regular expressions visualizer
#92Re: Regexper – Regular expressions visualizer
#93Re: Regexper – Regular expressions visualizer
#94Earlier 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.
Re: Regexper – Regular expressions visualizer
#95Back 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
#96M-x regexp-builder
Re: Regexper – Regular expressions visualizer
#97Earlier quoted context omitted.
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.
A dynamic visualization on the web 13 years ago? He may have been the first.
Depends on what you count as dynamic, but I think so yes. There was one in use at my Uni ~2000. Obviously there were no fancy canvas/svg options to work with client-side (though IIRC flash was very much a thing by then so that could have been used) so it produced an image server-side that was updated when you submitted a change.
Not entirely dynamic due to the manual post to the server for each update of the diagram, but it counts IMO. It could have been more automated via the JS/Dom methods available at the time I'm sure, I can think of a couple of ways, but I don't remember it being so.
> He may have been the first.
I'd say not the first. He may well have come up with the combination of ideas independently. How many times have you thought "X would be brilliant, I'm a genius" only to find when describing the idea to other that several "geniuses" preempted you and it already exists (or worse: it has been tried and proven to be a terrible idea in practice)! It has certainly happened to me a fair few times, and back then it wouldn't have been as easy to search out similar ideas/implementations.
Re: Regexper – Regular expressions visualizer
#98It'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…
Re: Regexper – Regular expressions visualizer
#99Here is a regexp to match an IPv4 address - looks quite nice and easy to understand compared to the regexp! In fact the visualisation makes it easy to spot the mistake. https://regexper.com/#'%5Cb((25%5B0-5%5D%7C2%5B0-4%5D%5B0-9%... (From https://stackoverflow.com/q/5284147/164234 )
If anyone wants to have a go at a more complete one, here are some test cases for you that it misses, using Google's well known public name server 8.8.4.4. These all work in the classic command line tools like ping on MacOS, Linux, and Windows:
134743044
8.525316
8.8.1028
POSIX and BSD also allow the numbers to be written in hex: 0x8080404
0x8.0x8.0x404
0x8.0x80404
0x8.0x8.0x4.0x4
or octal: 01002002004
010.2002004
010.010.02004
or mixed: 010.8.0x404Re: Regexper – Regular expressions visualizer
#100Earlier quoted context omitted.
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.
IPv4 addresses, according to POSIX, can be written in 4 forms:
A1.A2.A3.A4
A1.A2.B
A1.C
D
where Ai is an 8 bit number, B is a 16 bit number, C is a 24 bit number, and D is a 32 bit number. "10.1" is A1.C form.See the inet_addr man page if you are on Unix or a Unix-like system.