To można załatwić na poziomie samego regexa, dzięki grupom:
<?php
$regex = '/([0-9].[0-9]|[0-9].[0-9][0-9]|[0-9].[0-9][0-9].[0-9])/';
$inputs = [
'1.1',
'1.11',
'1.11.1'
];
foreach( $inputs as $input ) {
$matches = [];
preg_match( $regex, $input, $matches );
var_dump( $matches );
}
Niemniej te warunki wydają się powtarzalne, więc myślę, że da się to zrobić prościej, np:
<?php
$regex = '/\d(\.\d{1,2})+/';
$inputs = [
'1.1',
'1.11',
'1.11.1'
];
foreach( $inputs as $input ) {
$matches = [];
preg_match( $regex, $input, $matches );
var_dump( $matches );
}