Search code examples
replacefindnotepad++

Use Find-Replace to wrap strings that start and end with the same characters


Using Notepad++, this is to wrap HTML <img ... /> tags with <p> tags, but each full <img ... /> string contains different characters.

What I want to do is use Notepad++ "Find" tool to find each <img ... /> tag, then use "Replace" to wrap each <img ... /> with <p></p> tags.

This is to wrap the <img> tags faster than manually doing it.

Example:

Find...

<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" />

Replace by wrapping the <img ... /> tags with <p> tags

<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>

Any suggestions?

Thanks


Solution

  • You may try the following find and replace, in regex mode:

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

    Demo