extractImages static method

List<String> extractImages(
  1. String html
)

Extract all images with their URLs

Implementation

static List<String> extractImages(String html) {
  final images = <String>[];
  final strategies = [
    r'<img[^>]*src=[\"\x27]([^\"\x27]*)[\"\x27]',
    r'<meta[^>]*property=[\"\x27]og:image[\"\x27][^>]*content=[\"\x27]([^\"\x27]*)[\"\x27]',
  ];

  for (final pattern in strategies) {
    final matches = RegExp(pattern, caseSensitive: false).allMatches(html);
    for (final match in matches) {
      final imageUrl = match.group(1);
      if (imageUrl != null && imageUrl.isNotEmpty) {
        images.add(imageUrl);
      }
    }
  }

  return images.toSet().toList(); // Remove duplicates
}