I use regexes just often enough to be dangerous. I sometimes am hacking with grep and have a finite set of possible strings to match and will need to come up with a regex that will accept these but not another finite set of strings. Is there a tool that will suggest some regexes that can solve my problem? I know the general case is hard, but often I have finite enumerated lists and do not need the “best” regex, just a good enough one.
For example:
accept_list={‘bog’, ‘fog’, ‘frog’}
reject_list ={‘ogle’, ‘bogle’, ‘ogre’}
could be solved by ‘og$’, where I am assuming that $ indicates the end of the string.
I am not picky about the type; POSIX or PERL flavors are fine.
Is this a hard problem in the finite case?
In the finite case this is very easy since regex includes alternation (or):
For example accepts only the strings
bog,fog, andfrog, while rejecting all other strings.So, indeed, it is very easy to come up with a regular expression that accepts any finite language.