我不知道“相关性”是否是真正的问题。每个都是相关的,并且每个都将按照您的建议匹配“1234567”。但是,正如您所说,一个 ("1234.*") 更具体。使用正则表达式,特异性非常好(在这样的简单情况下),有时您可以深入研究它,直到您意识到您根本不需要一个(正则表达式)。正则表达式规则#1:如果不需要,不要使用它们。例如,要匹配“1234567”,我会选择:
$source = '1234567';
if ( stripos( $source, '1234' ) === 0 ) {
$foo = substr( $source, 4 );
// $source began with '1234' and $foo holds the rest
} else {
// it didn't begin with '1234'
}
That's a PHP example, but the idea is that, since you've honed your accepted value in so tightly, you don't even need PCRE anymore. "Relevancy" won't really tell you much about a regular expression (how would you define "relevancy" in this context?), however I think specificity a more objective measurement, and being able to use non-regex string functions instead would sure as heck be very measurably specific (in fact, it's boolean - are there regular expression or not?).
Outside of being able to reduce the regex out of the equation: To measure the specificity of a given regular expression, simply compare (heuristically, if necessary) how many different values would satisfy the expression. The expression with the least score in this test would prove the most specific.