Live data from Hacker News

RegExr 2.0

regexr.com

11–20 of 47 posts

Re: RegExr 2.0

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

Re: RegExr 2.0

#12
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)

[deleted]

Re: RegExr 2.0

#13
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)

"aaa" is a valid regex that matches the string "aaa". If you have special characters in your source string, many libraries have a regex for escaping them. So, generating a regex to match your exact string is trivial. Even matching a group of strings is trivial via (aaa|bbb|etc), though it gets long.

Given that, what I think you're really asking is, "how do I automatically generate a regex of optimal conciseness given a set of inputs I'd like to match, and maybe a bunch of other inputs I want to avoid matching?"

This looks like it iteratively does what you want: http://regex.inginf.units.it/ (Note that when I went there, it said "6 slots available", presumably because everything runs server-side. If a bunch of people pile in there, you probably won't actually be able to test it due to limited resources on their part.)

Re: RegExr 2.0

#14
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 problem with that is, given a corpus with a set of tokens { T0, T1, T2 ... }, I can give you a regex that will match the corpus!

  "[T0 T1 T2 ... ]*"
or even

  ".*"
So it will match everything in your corpus! But unfortunately, it will match a whole lot you don't want, too.

So ideally you want a regex that matches everything in your corpus, but nothing outside the language you are trying to describe. This requires both positive and negative learning examples. The problem is that for most applications, you'd need a lot of negative examples.

Source: Working on this exact problem for graduate research

Re: RegExr 2.0

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

T0 | T1 | T2 | ... would match exactly the correct thing with all positive examples, and (T0 | T1 | T2) & !(CE1 | CE2 | CE3) would match exactly the correct thing with positive and negative examples.

But that's pretty stupid, because you don't generalize beyond your examples.

What's your approach?

edit: removed random conjecture

Re: RegExr 2.0

#17
post #15

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…

T0 | T1 | T2 | ... would match exactly the correct thing with all positive examples, and (T0 | T1 | T2) & !(CE1 | CE2 | CE3) would match exactly the correct thing with positive and negative examples. But that's pretty stupid, because you don't generalize beyond your examples. What's your approach? edit: removed random conjecture

You have to have some sort of heuristic that determines what a "good" regex is, since there are undoubtedly multiple regexes that describe a corpus.

A simple heuristic is the smallest regex.

So in your example, given the training examples:

  aba
  abaa
  aaaaba
and the counter examples:

  abba
  ba
  ab
It's clear to a human I probably want to match "a+ba+". That's clearly much smaller than ("aba" | "abaa" | "aaaaba") & !("abba" | "ba" | "ab"), so it would be a "better" regex.

Re: RegExr 2.0

#19
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

same here :(

Re: RegExr 2.0

#20
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?

Just to make it clear: It does not even support the basic Latin-1 charset correctly. Matching my family-name requires manual intervention. This is sad.

It seems a very nice regex page otherwise.

Post reply on HN