Wednesday 10 July 2019

Generalized Regex from a set of String

I have this problem. I need to find automatically a way to generate a regex that match a set of string.



For example, given the set of string in input:



S = ["Casino Royale (1928)", "Mission Goldfinger", "A view to a kill"]


create iterating at the start a regex that match the first string, so:




regex1 = "\w{6}\s\w{6}\s\(\d{4}\)"


then compare regex1 with the second string, so:



regex2 = "\w{6-7}\s\w{6-10}(\s\(\d{4}\))?"


and then with the last string, so the final output is:




regex_output = "\w{1-7}\s\w{4-10}(\s\w{2}\s\w\s\w{4}|\s\(\d{4}\))?"


I would like to if it is possible to realize. Maybe it is a problem of complexity theory, maybe.



Thanks in advice.

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...