I'm looking for a bit of code that will:
Given regular expression E, derive the longest string X
such that for every S, X is a substring of S iff S will match E
examples:
E = "a", X = "a"
E = "^a$", X = "a"
E = "a(b|c)", X = "a"
E = "[ab]", X = ""
context: I want to match some regular expressions against a data store that only supports substring searching. It would be nice to optimize the regular expression searching by applying a substring search to the data store to reduce the amount of data transferred as much as possible.
example 2:
If I want to catch "error foo", "error bar", "error baz", I might specify
error: (foo|bar|baz)
and send
search "error: "
to the data store, and then regexping the returned items.
Thanks!