RegEx to remove carriage returns between

tags

前端 未结 7 543
臣服心动
臣服心动 2021-01-07 07:57

I\'ve stumped myself trying to figure out how to remove carriage returns that occur between

tags. (Technically I need to replace them with spaces, not

相关标签:
7条回答
  • 2021-01-07 08:51
    [\r\n]+(?=(?:[^<]+|<(?!/?p\b))*</p>)
    

    The first part matches one or more of any kind of line separator (\n, \r\n, or \r). The rest is a lookahead that attempts to match everything up to the next closing </p> tag, but if it finds an opening <p> tag first, the match fails.

    Note that this regex can be fooled very easily, for example by SGML comments, <script> elements, or plain old malformed HTML. Also, I'm assuming your regex flavor supports positive and negative lookaheads. That's a pretty safe assumption these days, but if the regex doesn't work for you, we'll need to know exactly which language or tool you're using.

    0 讨论(0)
提交回复
热议问题