Are you sure, that you don't lose any data? When I use your regex I do:
PHP Code:
$text = '
1234,
khjkh,
oh0w8,
123 kg,
453,
swf,
eraz,
564aw,
989879,
s4wefe,
awtw
';
//$regex = '/(?:\n|\r\n)(?:[^0-9]+[^,])/';
$regex = '~\r?\n[^0-9]+[^,]~'; //which is the same as yours, only more concise
$repl = preg_replace($regex, " ", $text);
echo "<pre>" . $text . "</pre>";
echo "<pre>" . $repl . "</pre>";
Output:
Code:
1234,
khjkh,
oh0w8,
123 kg,
453,
swf,
eraz,
564aw,
989879,
s4wefe,
awtw
1234, w8,
123 kg,
453, 64aw,
989879, wefe,
To solve your problem you could use a negative lookahead:
PHP Code:
$text = '
1234,
khjkh,
oh0w8,
123 kg,
453,
swf,
eraz,
564aw,
989879,
s4wefe,
awtw
';
$regex = '~\r?\n(?!\d+,)~';
$repl = preg_replace($regex, " ", $text);
echo "<pre>" . $text . "</pre>";
echo "<pre>" . $repl . "</pre>";
Output:
Code:
1234,
khjkh,
oh0w8,
123 kg,
453,
swf,
eraz,
564aw,
989879,
s4wefe,
awtw
1234, khjkh, oh0w8, 123 kg,
453, swf, eraz, 564aw,
989879, s4wefe, awtw
Bookmarks