# Learning a regex from string examples? [duplicate]

Given some strings, is there some algorithm (and program that implement such an algorithm) that can create a regex which matches some of the given strings and not the other given strings?

Note that the given strings are not all the strings that will be met by the regex. I hope the regex can generalize well on other strings not given (just like machine learning algorithms), but not necessarily achieve 100% accuracy.

Also it will be great if such an algorithm can take into account the efficiency of implementing regex matching

Thanks.

## marked as duplicate by Raphael♦Mar 14 '15 at 18:44

• How many strings some refers to in which matches some of the given strings and not the other given strings? ? it may be 2,3,4 ...?! – M a m a D Mar 14 '15 at 17:14