【问题标题】:How to delete "\r\n", but only in certain sections of my text?如何删除“\r\n”,但仅限于我的文本的某些部分?
【发布时间】:2014-05-27 10:58:17
【问题描述】:

如何使用正则表达式删除下面文本的 <out>...</out> 块的所有 \r\n 字符(将其转换为仅 1 行)?

<nx1>home</nx1>
<nx2>living</nx2>
<out>text one
text continues
and at last!</out>
<m2>dog</m2>

此文本示例的最终结果应为:

<nx1>home</nx1>
<nx2>living</nx2>
<out>text one text continues and at last!</out>
<m2>dog</m2>

【问题讨论】:

  • 我正在使用 EditPad Pro 正则表达式引擎;我尝试使用环视但没有成功;某事喜欢:(?)\r\n

标签: regex editpad


【解决方案1】:

搜索

(?<=<out>(?:(?!</?out>).)*)\r\n(?=(?:(?!</?out>).)*</out>)

并用一个空格替换所有内容。在 EditPad Pro 7.3.1 上测试。确保选择“点”选项,这样点也匹配换行符。

说明:

(?<=               # Look behind to assert that there is...
 <out>             # an <out> tag before the current position,
 (?:(?!</?out>).)* # followed by anything except <out> or </out> tags
)                  # End of lookbehind
\r\n               # Match \r\n
(?=                # Look ahead to assert that there is...
 (?:(?!</?out>).)* # any number of characters ahead (except <out>/</out> tags)
 </out>            # followed by an </out> tag
)                  # End of lookahead

【讨论】:

  • 非常感谢;它工作得很好;你能描述一下这种模式吗?
  • EditPad 专业团队可以通过添加使用二级、三级、...模式的可能性来制作一款令人惊叹的软件;我的意思是使用像\Q&lt;out&gt;\E.+?\Q&lt;/out&gt;\E 这样的简单模式,我们突出显示摘录文本以继续搜索,然后在突出显示的文本中简单地找到\r\n 并将其替换为空格!
  • 赞成解释...我讨厌正则表达式
猜你喜欢
  • 1970-01-01
  • 2014-05-29
  • 1970-01-01
  • 1970-01-01
  • 2020-01-27
  • 1970-01-01
  • 2015-04-01
  • 1970-01-01
  • 2013-08-10
相关资源
最近更新 更多