views:

117

answers:

3

I need a model for finding all of the regular expressions that would match a particular string. Basically, I need an algorithm for doing what I do to generate a regex search string from some pattern.

My purpose for this to create a list of potential regular expressions from a selection of text and order that list from least specific (i.e. string of characters with abitrary length) to most specific (i.e. the string itself) to be used in text editor.

+1  A: 

There is infinite regular expressions matching any given string, so obviously you will need some more criteria to make a useful list.

The best I can say, you should probably make a list of sensible ways to generate a reg ex from a string, and present the results.

Some suggestions:

  • Alphanumeric
  • Alphanumeric + whitespace
  • Letters
  • Upper case only
  • Lower case only
  • Numbers
  • All of the above fixed at the length of the string
  • Match for the string with letters being exchangeable for other letters, and numbers likewise
  • Same as above, but with sequences of letters and numbers not being of fixed length
  • Same as the two above, but with lower case and upper case letters not being exchangeable
  • Same as those above with only numbers being exchangeable
  • If there is repeated sequences, try to make some expressions that require similar repetition

If you want to make many expressions to choose from, you might want to sort them by categories and subcategories rather than specificness.

eBusiness
A: 

My goal is similar to txt2re.com, but with an interface based on the afformentioned list and simultaneous highlighting of matched strings in the document. I've sent the author of the site an email and I am reading through Igor Krivokon's linked question

Mirai
A: 

You can peep at a product that do that

http://www.regexmagic.com/

But of course it doesn't find ALL the regexes that match a particular string ... because it is not a fair problem for a poor computer

belisarius