Edit: This had been closed as too broad without justification and I believe it's a mistake. One question was also proposed as a duplicate : Regex: Determine if two regular expressions could match for the same input? It is similar but mine is an R question which asks not if two expressions match the same, but if one's matches contains the matches of the other, and my ideal output is a practical function, or cues that I can use to build one, the theory linked is a bit overwhelming for a R programmer. As a side note this linked question has 40+ votes and was never closed despite being broader than mine.
I want to assess if a regex pattern will match in any circumstances what another pattern matches.
For instance .*
matches everything, so, naming fun
the function I would like to have, we'd have fun(".*", "foo")
to be TRUE
because if "foo"
is matched, ".*"
will be matched as well.
Other calls returning TRUE
would be:
fun("[ab]","a")
fun("\\D","^\\D{2}$")
If I revert the arguments of the examples above, or if I have two patterns that might overlap, it should return FALSE
.
I want to be able to do this from the patterns alone, not by testing them on data first. How can I do that ?