1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
<?php
// motif
$myPattern = '/^[0-9A-F]{2}(?:[-_][0-9A-F]{2})*$/';
// tests
$myString = "1A";
preg_match($myPattern, $myString, $matches); print_r($matches); print "<hr/>";
$myString = "1A_2A";
preg_match($myPattern, $myString, $matches); print_r($matches); print "<hr/>";
$myString = "1A-1F_2A_30-4F";
preg_match($myPattern, $myString, $matches); print_r($matches); print "<hr/>";
$myString = "1M";
preg_match($myPattern, $myString, $matches); print_r($matches); print "<hr/>";
$myString = "1M-1F_2A_30-4F";
preg_match($myPattern, $myString, $matches); print_r($matches); print "<hr/>";
$myString = "1B-1M_2A_30-4F";
preg_match($myPattern, $myString, $matches); print_r($matches); print "<hr/>";
$myString = "1B-1M_2A _30-4F";
preg_match($myPattern, $myString, $matches); print_r($matches); print "<hr/>";
$myString = "1B-1M_2_30-4F";
preg_match($myPattern, $myString, $matches); print_r($matches); print "<hr/>"; |
Partager