I am trying to strip newlines only from the urls in a text body while preserving all other newlines. The other newlines will be converted into <p>
tags later on, so it is important to keep them as is.
Given this text example with multiple tags with urls (this should be all on one line, line breaks are only for readability purposes):
"Lorem ipsum dolor <a href=\"http://www.example.org/page?\nid=161&_te=mj\">sit</a> amet,
consectetur adipiscing elit. \nDuis facilisis eros at sem faucibus finibus. Integer tempus
lectus sed gravida efficitur. Proin dignissim pretium arcu, accumsan gravida ex tincidunt
eget. Maecenas ac finibus elit. Maecenas aliquam fermentum nisl quis egestas.
<a href=\"http://www.example.org/page?id=341\n&_te=mp\">Nulla placerat est vitae convallis</a>
euismod. Praesent id elit a ligula hendrerit lacinia."
I have found a way to isolate one of the links in the text by using this pattern
\bhttps?:\/\/[^<>]+(?:\([\w\d]+\)|[^,[:punct:]\s]|\/)
However I am totally lost on how to then strip the newline out of that substring, or only match on the newline within the url pattern. Ultimately this is going into some php code and will need to replace all cases of this within the string, so if there are better php utility methods that will do this, I'm all ears!
What I am going for is this (only \n in urls are removed, all others preserved):
"Lorem ipsum dolor <a href=\"http://www.example.org/page?id=161&_te=mj\">sit</a> amet,
consectetur adipiscing elit. \nDuis facilisis eros at sem faucibus finibus. Integer tempus
lectus sed gravida efficitur. Proin dignissim pretium arcu, accumsan gravida ex tincidunt
eget. Maecenas ac finibus elit. Maecenas aliquam fermentum nisl quis egestas.
<a href=\"http://www.example.org/page?id=341&_te=mp\">Nulla placerat est vitae convallis</a>
euismod. Praesent id elit a ligula hendrerit lacinia."
This is a very specific question and does not match any of the duplicates associated with it. I am dealing with a legacy system and cannot solve this using DOM parsing. Please answer this question using regex.