fork download
  1. <?php
  2.  
  3. $re = '/(\*[A-Z0-9]{2})(.*?)(?=(?!\1)\*[A-Z0-9]{2}|$)/';
  4. $str = '*01the title*35the author*A7other useless infos*AEother useful infos*AEsome delimiters can be there multiple times';
  5. $res = [];
  6. if (preg_match_all($re, $str, $m, PREG_SET_ORDER, 0)) {
  7. foreach ($m as $kvp) {
  8. $tmp = preg_split('~\*[A-Z0-9]+~', $kvp[2]);
  9. if (count($tmp) > 1) {
  10. $res[$kvp[1]] = $tmp;
  11. } else {
  12. $res[$kvp[1]] = $kvp[2];
  13. }
  14. }
  15. print_r($res);
  16. }
  17.  
Success #stdin #stdout 0s 82624KB
stdin
Standard input is empty
stdout
Array
(
    [*01] => the title
    [*35] => the author
    [*A7] => other useless infos
    [*AE] => Array
        (
            [0] => other useful infos
            [1] => some delimiters can be there multiple times
        )

)