好吧,我认为不会有正则表达式的解决方案.
所以在这里我编写了你需要的功能:
function isValidDigitExpression($string) {
$flag = preg_match('/^(\d+)\-(\d+)\-(\d+)$/', $string, $matches);
if (!$flag) return false;
// Check correct sorting by splitting digit string to array
for ($i = 1; $i <= 3; $i++ ) {
$block[$i] = str_split($matches[$i]);
$compare = $block[$i];
sort($compare);
if ($compare != $block[$i]) return false;
}
// Compare Min and Max digits of neighboring digit blocks
return (max($block[1]) <= min($block[2]) and max($block[2]) <= min($block[3]));
}
$string = "123-34-356"; // Failure, because 3 < 4 comparing Block 2 and Block 3
echo isValidDigitExpression($string) ? "SUCCESS" : "FAILURE";