【问题标题】:Use Find-Replace to wrap strings that start and end with the same characters使用 Find-Replace 包装以相同字符开头和结尾的字符串
【发布时间】:2021-09-20 07:05:56
【问题描述】:

使用记事本++,这是用<p>标签包装HTML <img ... />标签,但每个完整的<img ... />字符串包含不同的字符。

我想要做的是使用记事本++“查找”工具找到每个<img ... />标签,然后使用“替换”将每个<img ... />包装成<p></p>标签。

这是为了比手动包装<img>标签更快。

例子:

寻找...

<img src="https://example.com/image-icon-9.jpg" alt="text here" class="alignleft size-full" title="test-here" width="50" height="50" />
<img src="https://example.com/image-icon-12.jpg" alt="text here" class="alignleft size-full" title="test-here" width="50" height="50" />
<img src="https://example.com/image-icon-5.jpg" alt="text here" class="alignleft size-full" title="test-here" width="50" height="50" />
<img src="https://example.com/image-icon-8.jpg" alt="text here" class="alignleft size-full" title="test-here" width="50" height="50" />

&lt;p&gt;标签包裹&lt;img ... /&gt;标签

<p><img src="https://example.com/image-icon-9.jpg" alt="text here" class="alignleft size-full" title="test-here" width="50" height="50" /></p>
<p><img src="https://example.com/image-icon-12.jpg" alt="text here" class="alignleft size-full" title="test-here" width="50" height="50" /></p>
<p><img src="https://example.com/image-icon-5.jpg" alt="text here" class="alignleft size-full" title="test-here" width="50" height="50" /></p>
<p><img src="https://example.com/image-icon-8.jpg" alt="text here" class="alignleft size-full" title="test-here" width="50" height="50" /></p>

有什么建议吗?

谢谢

【问题讨论】:

    标签: replace find notepad++


    【解决方案1】:

    您可以在正则表达式模式下尝试以下查找和替换:

    Find:    <img.*?/>
    Replace: <p>$0</p>
    

    Demo

    【讨论】:

    • 我忘了添加,当使用上面的这个方法时,在 Notepad++ 的“查找 - 替换”中,确保:“正则表达式”被选中(并且...)“.matches newline”被取消选中.
    猜你喜欢
    • 1970-01-01
    • 2021-11-28
    • 2012-12-03
    • 1970-01-01
    • 2021-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多