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
Find img tag to add ALT Attribute when necessary
-
- Posts: 1
- Joined: Mon Oct 17, 2005 6:40 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
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