$re = '/^(?=.*\bDATA1="(?<d1>[^"]+)"\h*)?(?=.*\bDATA2="(?<d2>[^"]+)"\h*)?(?=.*\bDATA3="(?<d3>[^"]+)"\h*)?(?=.*\bDATA4="(?<d4>[^"]+)"\h*)?(?=.*\bDATA5="(?<d5>[^"]+)"\h*)?.*/m';
$str = 'DATA1="8DE" DATA2="322" DATA3="20" DATA4="19.99" DATA5="0.01"
DATA1="FE4" DATA2="222" DATA4="400" DATA3="400" DATA5="0.00"
DATA1="CE3" DATA2="444" DATA4="60" DATA5="0.00" DATA3="60"
DATA1="MME" DATA3="20" DATA4="20" DATA5="0.00"
DATA2="667" DATA4="30" DATA3="30" DATA5="0.00" DATA1="MH4"';
$subst = "${d1}\t\t${d2}\t\t${d3}\t\t${d4}\t\t${d5}";
$result = preg_replace($re, $subst, $str);
echo "The result of the substitution is ".$result;
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php