regex - 从两个字符串替换特定字符串
问题描述
我想从两个字符串中替换一个特定的字符串。我想删除<br />
删除and然后用<blockquote>
and替换</blockquote>
<blockquote>
<pre>
</blockquote>
</pre>
<blockquote>
data.frame()<br />
mutate()<br /></blockquote>
最终结果应如下所示 -
<pre>
data.frame()
mutate()
</pre>
我尝试了以下解决方案,但它选择了块引用之间的所有内容。
(?s)^\t*<blockquote>(.|\r\n)*?</blockquote>
解决方案
- Ctrl+H
- 找什么:
\A.*?(?:<blockquote>|\G(?!<))(?:(?!</blockquote>).)*?\K<br />
- 用。。。来代替:
LEAVE EMPTY
- 取消选中匹配案例
- 检查环绕
- 检查正则表达式
- 查看
. matches newline
- Replace all
解释:
\A # beginning of string
.*? # 0 or more any character, not greedy
(?: # start non capture group
<blockquote> # literally open tag
| # OR
\G # restart from last match position
(?!<) # negative lookahead, make sure we haven't "<" after
) # end group
(?: # start non capture group
(?!</blockquote>) # negative lookahead, make sure we haven't after a closing tag
. # any character
)*? # end group, may appear 0 or more times, not greedy
\K # forget all we have seen until this position
<br /> # literally
鉴于:
<tag>
blah<br />
blah<br />
</tag>
<blockquote>
data.frame()<br />
mutate()<br /></blockquote>
<tag>
blah<br />
blah<br />
</tag>
<blockquote>
data.frame()<br />
mutate()<br /></blockquote>
<tag>
blah<br />
blah<br />
</tag>
给定示例的结果:
<tag>
blah<br />
blah<br />
</tag>
<blockquote>
data.frame()
mutate()</blockquote>
<tag>
blah<br />
blah<br />
</tag>
<blockquote>
data.frame()
mutate()</blockquote>
<tag>
blah<br />
blah<br />
</tag>
屏幕截图(之前):
屏幕截图(之后):
推荐阅读
- angular - 为什么在 Windows 10 中,即 Angular 1.5.8 中,当 XMLHttpRequest xhr.open ('post', 'http://localhost' true) 时出现“拒绝访问”错误
- pouchdb - 中止对 pouchdb 的查询
- javascript - SubtleCrypto ArrayBuffer 键到字符串
- jsf - JSF 2.3 f:websocket java.lang.AbstractMethodError
- mysql - mysql - 计算日期之间的销售利润
- python-3.x - 脚本中包的相对导入:Python3
- python - 在 PyQt4 中使用 FigureCanvas 创建几个弹出图
- scala - Spark 和 Scala:saveAsTextFile() 异常
- javascript - 在 nodeJS 应用程序中打印我的组树的问题
- mysql - MySQL每日数据从特定时间开始