I have a line like this:
$data = 'id=1 username=foobar comment=This is a sample comment';
And I would like to remove \n in the third field ( comment=... ).
I have this regex that serves my purpose, but not so well:
preg_replace('/\bcomment=((.+)\n*)*$/', "comment=$2 ", $data);
My problem is that every match in the second group overwrites the previous match. So instead:
'... comment=This is a sample comment'
I ended up with this:
'... comment= comment'
Is there a way to store intermediate backlinks in a regular expression? Or do I need to map each occurrence within a loop?
Thanks!
source share