[pcre-dev] determine regular expression specificity

Kezdőlap
Üzenet törlése
Szerző: Praet Paul
Dátum:  
Címzett: pcre-dev@exim.org
Tárgy: [pcre-dev] determine regular expression specificity
Hi,


Given the following regular expressions:
 - alice@[a-z]+\.[a-z]+
 - [a-z]+@[a-z]+\.[a-z]+
 - .*

The string alice@??? will obviously match all three regular expressions. In the application I am developing, we are only interested in the 'most specific' match. In this case this is obviously the first one.
Unfortunately there seems no way to do this. A possible way would be to keep the regular expressions sorted on descending specificity and then simply take the first match. Of course then the next question would be how to sort the array of regular expressions. It is not an option to give the responsibility to the end-user to ensure that the array is sorted. So I hope you guys could help me out here...


Thanks !!


Paul


[Reference to stackoverflow question: http://stackoverflow.com/questions/3611860/determine-regular-expressions-specificity]