Find img tag to add ALT Attribute when necessary

General discussions about Advanced Find and Replace
Post Reply
Posts: 1
Joined: Mon Oct 17, 2005 6:40 pm

Find img tag to add ALT Attribute when necessary

Post by Georges.Lauret » Mon Oct 17, 2005 6:48 pm

I want to find <img> tag that DONT Contains ALT, and when found add ALT="".
The tags that contains an attribute MUST remain unchanged of course...

Thank you for help

Site Admin
Posts: 1220
Joined: Mon Jan 31, 2005 5:32 pm

Post by Abacre » Wed Nov 30, 2005 12:25 pm


The task is solvable with Advanced Find and Replace.
One small inconvenience: in classical regular expressions there is no
"does not contains" operator for lateral strings.
But AFR can do the task any way in 3 steps.

Go to main menu - Action - Options - Batch Replace
check "Modifier S"

Go to Batch replace tab, check on "Use regular expressions".
Put into the grid 3 rows:

Search for:
<img(.*) alt=(.*)>
Replace with:
<temp_img$1 alt=$2>

Search for:
Replace with:
<img$1 alt="">

Search for:
Replace with:

Press Execute button.

That's all I verified it works perfectly.

With first search/replace pair we temporarily rename <img> tag already
having "alt" with new tag name: <temp_img
Then with second search/replace pair we add alt="" to all <img> tags
which don't having yet alt tag.
With the third search/replace pair we rename back <temp_img into <img
Kind regards,
Abacre Limited

Post Reply