tags:

views:

53

answers:

1

I know there are a lot of tools that allow you to create regular expressions and test regular phrases against them, but is there a tool that allows you to type just a regular phrase or word, etc and it will generate the regular expression for you. For example, typing:

xyz555.. would generate the correct regular expression. It may not be the most ideal expression, but it would be a useful learning tool.

+3  A: 

Because such analysis can't be done deterministically. It's impossible to take a single sample (or any particular number of samples) and generate a pattern.

For example, your example data could mean three alphabetic characters followed by three numeric characters...

...or it could be any number of alphabetic characters followed by three numerics

...or three alphabetic followed by three '5' characters.

It's impossible to determine exactly what the pattern is when more than one pattern fits the data.

Adam Robinson
+1 I think we would all love a tool like this :P
Robert Greiner
@Adam: Can you explain in what you mean in a little more detail. In my example, I actually mean 3 alphabetic characters followed by three numeric characters.
Xaisoft
@Xaisoft: I realize that's what you mean; my point is that the application would have no way of *knowing* that's what you mean. It could come up with a theoretically unlimited number of different patterns that would all fit that data, but only one of them would be right.
Adam Robinson
Thanks for the update. I guess one you would have to be really specific on what you mean when you create a phrase? But it seems like hard work.
Xaisoft
@Xaisoft: The only way to do it would be to allow the user to specify exactly what the pattern is...which would simply be creating a new regular expression language.
Adam Robinson
@Xaisoft: Well if we humans don't really know what you mean by `xyz`, how can you expect a computer to know that?
Otto Allmendinger
@Otto: That's pretty much the answer I was looking for.
Xaisoft