fork download
  1. <?php
  2.  
  3. $str = "FORT/310117/200826/12979898000170";
  4. //$str = "FORT/310117/200826";
  5. //$str = "FORT/12979898000170";
  6. preg_match_all('/(?|(\b\d{6}\b)(?=.+?\b\d{14}\b)|(?<=\b\d{14}\b).+?(\b\d{6}\b)|(\b\d{14}\b)(?=.+?\b\d{6}\b)|(?<=\b\d{6}\b).+?(\b\d{14}\b))/', $str, $matches, PREG_SET_ORDER);
  7. var_dump($matches);
  8. foreach($matches as $m) {
  9. echo $m[1] . "\n";
  10. }
Success #stdin #stdout 0s 82624KB
stdin
Standard input is empty
stdout
array(2) {
  [0]=>
  array(2) {
    [0]=>
    string(6) "310117"
    [1]=>
    string(6) "310117"
  }
  [1]=>
  array(2) {
    [0]=>
    string(22) "/200826/12979898000170"
    [1]=>
    string(14) "12979898000170"
  }
}
310117
12979898000170