Live data from Hacker News

RegExr 2.0

regexr.com

21–30 of 47 posts

Re: RegExr 2.0

#21
Regex testing is cool, but there are dozens of these kinds of tools and I'd really love to see some other kinds of regex tools

- A list generator. Enter a regex, set repetition operator constraints (e.g. ->{0,3}, +->{1,3}, .->[A-Z0-9 ], etc.) and have it exhaustively generate a list of matching strings. This is helpful when you have a regex that matches your test strings, but also to let you know what else* it'll match. The constraints are to keep it from generating infinite lists. Even if it jams out tens or hundreds of thousands of produced strings, it's still useful. I've found that most people just build up the first regex that will "match" their input text, and move on without thinking about all the edge cases they've just introduced.

- A regex assembler optimizer. Give it a few regexes, have it assemble them into one large regex and optimize it. It's got to do better than just | or'ing all the regexes together. I've seen some work done on using trie variants to do this, but have no idea how far along the work is on this.

- A regex list generator. Give it a list of strings you want to match and have it generate a regex. A sliding "fuzziness" control could tell it to take alternates in the same character position and substitute either

1. Just the characters in the given list - a, t and q in the same position generates a|t|q

2. A representative narrow character range - if I give it a|t|q it knows to use [A-Z] while a|t|q|4 might generate [A-Z0-9]

3. A larger character range, a|t|q might just go ahead and produce [A-Z0-9]

4. An even larger character range, whatever it is, just use .

And maybe another slider for repetitions, so if I end up with [A-Z][A-Z][A-Z], should it just produce [A-Z]{3} or can I go ahead and have it [A-Z]+

Jam the result through an optimizer (see previous idea above) to clean up the regex and maybe even run it through the list generator to check if it produces only what you want.

Re: RegExr 2.0

#22
Very nicely done. As someone else pointed out there are quite a few of these tools, but I think you've done a really nice job with this one. One suggestion: make the reference easier to scan at a top level as opposed to drilling down.

Re: RegExr 2.0

#24
post #7

I'm guessing the following is either near-impossible or pure-impossible, but: Is there a tool that allows you to highlight portions of a string and generate a corresponding regex? (i.e. the inverse of RegExr)

Here is the problem with that: Consider the string abcdefgh Guess what!? I have the perfect regex to match your string. "abcdefgh" So given a string literal, there is always a regex to match that literal. Namely, the literal itself. Really, what you want is a tool that, given several examples, will generate a regex that matches all of them. So you'd give it: aaaaabaa aabaaa aba abaaaaa And it'd generate "a+ba+" The p…

Since you're a researcher I must be missing something. But since regexps are closed under union, what is the problem with taking the union of all of them? I'm imagining that it would be conceptually simple to hook up all of the non deterministic state machines such that you get a non deterministic state machine which is the union of all of them. Then convert it to a deterministic state machine. You might get state explosion, but at least you would have found some machine to recognize the language. Is state minimization simple (complexity wise)? Is it even possible to find a decently small DSM in the general case (not necessarily the most minimal machine)?

Re: RegExr 2.0

#25
post #21

Regex testing is cool, but there are dozens of these kinds of tools and I'd really love to see some other kinds of regex tools - A list generator. Enter a regex, set repetition operator constraints (e.g. ->{0,3}, +->{1,3}, .->[A-Z0-9 ], etc.) and have it exhaustively generate a list of matching strings. This is helpful when you have a regex that matches your test strings, but also to let you know what else* it'll mat…

Why don't you take a crack at it?

Re: RegExr 2.0

#26
post #5
post #2

> Uh-oh, it looks like your browser is not supported. > RegExr only supports modern desktop browsers. I'm using Firefox 30 on Ubuntu. I think it's plenty modern :)

I get the same message with chrome 34 on android 4.4.2

Pretty sure Android is not commonly considered a desktop system ;) Though mobile (or at least tablet) support would be cool

Re: RegExr 2.0

#27
post #24

Earlier quoted context omitted.

Here is the problem with that: Consider the string abcdefgh Guess what!? I have the perfect regex to match your string. "abcdefgh" So given a string literal, there is always a regex to match that literal. Namely, the literal itself. Really, what you want is a tool that, given several examples, will generate a regex that matches all of them. So you'd give it: aaaaabaa aabaaa aba abaaaaa And it'd generate "a+ba+" The p…

Since you're a researcher I must be missing something. But since regexps are closed under union, what is the problem with taking the union of all of them? I'm imagining that it would be conceptually simple to hook up all of the non deterministic state machines such that you get a non deterministic state machine which is the union of all of them. Then convert it to a deterministic state machine. You might get state ex…

My reply to nmrm might answer your question.

Finding some regular expression that matches all of the positive examples and does not match all of the negative examples is trivial. Finding a good regular expression that does that is not.

State minimization does not mitigate this problem. As an aside, state minimization is a polynomial algorithm.

Given the positive examples:

  aba
  abaa
  aaaaba
and the negative examples:

  abba
  ba
  ab
we could make a regex that does something like ("aba" | "abaa" | "aaaaba") & !("abba" | "ba" | "ab"), but unfortunately, running a state minimization algorithm on this regex does not give you "a+ba+" because the two regex are not equivalent (they do not accept the same language).

So you can find plenty of regex that will match your examples and not match your counterexamples, but you cannot easily minimize them to what you do want.

Re: RegExr 2.0

#28
post #11
post #9

People just cannot do unicode even remotely properly. Just cannot. 𝄞 is one char, not two. привет is matched by \w+. PS there's some advanced stuff but where is basic [[:posix:]] char classes?

It doesn't support \p{} either for matching Unicode classes. e.g. \p{Lu} matches uppercase letters (so also Æ and Ö counts).

I couldn't find a way to add the /u or /s flag. There are only allowed /i, /g and /m :(

Re: RegExr 2.0

#30
post #2

> Uh-oh, it looks like your browser is not supported. > RegExr only supports modern desktop browsers. I'm using Firefox 30 on Ubuntu. I think it's plenty modern :)

I got the same message (FF28 Mac). Then I turned session cookies on and it worked.

Obviously they need to fix the error message...

Post reply on HN