// Matcher to find an image tag. The 'html' variable contains the HTML in question Matcher mImg = Pattern.compile("(?id)").matcher(html); // Matcher to find an ALT attribute (to be applied to an IMG tag's body within the same 'html' variable) Matcher mAlt = Pattern.compile("(?ix)\\b ALT \\s* =").matcher(html); // For each image tag within the html . . . while (mImg.find()) { // Restrict the next ALT search to the body of the just-found image tag mAlt.region( mImg.start(1), mImg.end(1) ); // Report an error if no ALT found, showing the whole image tag found above if (! mAlt.find()) System.out.println("Missing ALT attribute in: " + mImg.group()); } ----------------------------------------------------------------------------- Copyright 1997-2024 Jeffrey Friedl