Home » excel » html – Regular expression for Notepad++

html – Regular expression for Notepad++

Posted by: admin April 23, 2020 Leave a comment

Questions:

Long story short, I have a very large table (1200+ rows) from a custom Excel to html conversion, which is working beautifully, except for a final missing part. I’m no good with RegEx, and I think I need it for a Find and Replace in Notepad++. Below is what I have and what I need.

Input:

<td>image1</td>
<td>image2</td>
...
<td>image1242</td>

Needed output:

<td><img src="image1.png" alt="" /></td>
<td><img src="image2.png" alt="" /></td>
...
<td><img src="image1242.png" alt="" /></td>

Please advice!

How to&Answers:

Use this regular expression:

<td>image(.+)</td>

and the following pattern as a replacement:

<td><img src="image.png" alt"" /></td>

As a sidenote, it is usually not a good practice to parse HTML with regular expressions – in simple cases like this, it might be sufficient, but for anything more complicated, it would be much better to parse the HTML like XML file.

If you know some C#, you could use HTML Agility Pack for that.

Answer:

Do this way:-

Find What:

<td>image(\d+)</td>

Replace With:

<td><img src="image.png" alt="" /></td>

Refer the screenshot:

Find Replace with Regex