This question already has an answer here:
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