str.split(/(?<=\S)\s*(?=[А-ЯЁ])/).join(' ')
// или
str.replace(/(?<=\S)(?=[А-ЯЁ])/g, ' ')
// или
str.replace(/(\S)(?=[А-ЯЁ])/g, '$1 ')
// или
str.replace(/[А-ЯЁ]/g, (m, i) => i && str[~-i] !== ' ' ? ' ' + m : m)
$doc = new DOMDocument();
$doc->loadHTML($html);
$a = $doc->getElementsByTagName('a');
$result = array_map([ $doc, 'saveHTML' ], iterator_to_array($a));
$result = preg_split('/(?<=\/a>)(?=<a)/', $html);
// или
preg_match_all('/<a .*?>.*?<\/a>/', $html, $matches);
$result = $matches[0];
const lines = data.split('\n').map(n => n.replace(/X\S+/, 'hello, world!!'));