fork download
  1. <?php
  2.  
  3. $tests = [
  4. 'dasdas № 11-1111 dsasda 22 - 2222',
  5. '1 - 22 no match'
  6. ];
  7. $rex = '#(№\s*)?[\d]{2}\s*-\s*[\d]{4}#u';
  8.  
  9. foreach($tests as $str) {
  10. $match = [];
  11. $ok = preg_match_all($rex, $str, $match);
  12. echo $str . ' => ' . (
  13. $ok
  14. ? print_r($match[0], true)
  15. : '[NO MATCH]'
  16. );
  17. }
  18.  
Success #stdin #stdout 0.01s 82944KB
stdin
Standard input is empty
stdout
dasdas № 11-1111 dsasda 22 - 2222 => Array
(
    [0] => № 11-1111
    [1] => 22 - 2222
)
1 - 22 no match => [NO MATCH]