I'm trying to use a regular expression to find groups of spaces and replace them with another character like $
$teststring="00005e-000003 D21 3 0004ea-287342 D21 3 000883-d94982 D21 3 000f20-4c5241 D21 3 002561-e32140 D21 3 003018-a1a24f D21 3 00e039-0fe0fe D21 3 08000f-1eb958 D21 3 08000f-1ec4de D21 3 082e5f-498900 D21 3";
$pattern='/([0-9A-F]{6})-([0-9A-F]{6}) ([0-9A-F]+)\s{1,}([0-9]{1,})/i';
if (preg_match_all($pattern,$teststring,$matches, PREG_PATTERN_ORDER)) {
$data = $matches[0];
}
this is working in that based on my pattern, if i do a print_r on $data, it looks like:
Array (
[0] => 00005e-000003 D21 3
[1] => 0004ea-287342 D21 3
[2] => 000883-d94982 D21 3
}
what I'd like to do is replace all spaces with $ so the output looks like this:
Array (
[0] => 00005e-000003$D21$3
[1] => 0004ea-287342$D21$3
[2] => 000883-d94982$D21$3
}
Can you tell me how i can accomplish this?
Thanks.