很容易删除/替换标签但保留内容?

时间:2020-04-17 12:06:58

标签: notepad++

说我有很多文件,可以在其中看到与以下内容类似的结构: <li><p>text.</p><p>some other text.</p></li> 这不是我想要的。我想要以下内容: <li>text.<p>some other text.</p></li> 我知道如何找到这样的实例(<li><p>.*</p> <p>.*</p></li>),但是我不知道如何替换它们,而是保持内容不变。 甚至有可能吗?

2 个答案:

答案 0 :(得分:1)

  • Ctrl + H
  • 查找内容:(<li>)<p>(.+?)</p>
  • 替换为:$1$2
  • 检查 环绕
  • 检查 正则表达式
  • 全部替换

说明:

(<li>)          # group 1, open <li> tag
<p>             # open <p> tag
(.+?)           # group 2, 1 or more any character, not greedy
</p>            # close </p> tag

替换:

$1      # content of group 1 (<li>)
$2      # ccontent of group 2 (text.)

屏幕截图(之前):

enter image description here

屏幕截图(之后):

enter image description here

答案 1 :(得分:0)

对于我的用例

Find what:     <li><p>(.*?)</p><p>(.*?)</p></li>
Replace with:  <li>\1<p>\2</p></li>

Match Case: checked
Regular expression: checked
.matches newline: check
相关问题