I am working on an answer to the same problem that I have found so far: http://maple.cs.umbc.edu/~don/projects/ugrad-ht/dminer-ugradthesis.pdf
This is a graduate level research paper using perl regex, it has a workable definition for "the most specific regular expression", and triggers a warning if there are two regular expression expressions with the same specificity. It is partly based on the SELinux installation file, but aims to be faster and more accurate. Setfile leaves it to the user so that matches go from the most specific to the least specific and take the first match. This may cause some problems that the research paper must solve.
In principle, the most specific match is one that is not a superset of any other match. The difficulty in solving is to determine which sets are supersets of other sets; Of course, the answer to this depends on the circumstances for which regular expression is required. When you have a list of supersets, then it becomes a matter of eliminating matches. So with regex expressions' ^ /. * ',' ^ / Usr /.* 'and' ^ / home /.* ',' ^ /. * 'Is a superset of the other two, and the other two are mutually exclusive. In the correct implementation, if the two second ones were not mutually exclusive ("^" is missing), and none of them is a superset of the other, a warning or error should be issued to the user or user. For a given string, in order to check the correspondence, it must first be checked against any supersets (in this case "^ /. *"). If it does not match the superset, it cannot match any particular pattern. If it matches, then a test should be performed against each of the children of the superset (these sets can also be supersets of additional sets). If it does not match any of the children, then the most specific regular expression is a superset ('^ /. *'). If it corresponds to one of the children, then the process should be repeated with the associated grandchildren until there are no specific sets or none of the specific sets matches.
It is enough not to issue warnings about non-mutually exclusive non-super-sets unless an attempt is made to match strings that cannot be resolved. Consider the many regular expression expressions: '^ /. * ',' /usr.* 'and' /home.* '. The string '/ home / usr' will match all three, and an attempt to match should throw an error, since it is unclear if '/usr.*' or '/home.*' is intended as the most specific regular expression.
Depending on the reasons that need to be addressed, a valid list of regular expressions that are not supersets of any other suitable regular expressions may be the ideal solution. In this case, '/ home / usr' should return '/home.*' and '/usr.*', but not '^ /. * '.
The document provides code examples, but is described only in abstract terms. I will try to write some actual code to implement it, or maybe write to the author and see if I can get the code, if I get something that really works, I will post it here.