Page 1 of 1

Find img tag to add ALT Attribute when necessary

Posted: Mon Oct 17, 2005 6:48 pm
by Georges.Lauret
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

Posted: Wed Nov 30, 2005 12:25 pm
by Abacre
Hi,

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:
<img(.*)>
Replace with:
<img$1 alt="">

Search for:
<temp_img
Replace with:
<img

Press Execute button.

That's all I verified it works perfectly.

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