Find img tag to add ALT Attribute when necessary

General discussions about Advanced Find and Replace
Post Reply
Georges.Lauret
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

Abacre
Site Admin
Posts: 1201
Joined: Mon Jan 31, 2005 5:32 pm
Contact:

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

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
Kind regards,
Abacre Limited
http://www.abacre.com
support@abacre.com

Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests