extractLinks static method

List<String> extractLinks(
  1. String html
)

Extract all links

Implementation

static List<String> extractLinks(String html) {
  final links = <String>[];
  final pattern = r'<a[^>]*href=[\"\x27]([^\"\x27]*)[\"\x27]';

  final matches = RegExp(pattern, caseSensitive: false).allMatches(html);
  for (final match in matches) {
    final link = match.group(1);
    if (link != null && link.isNotEmpty && link.startsWith('http')) {
      links.add(link);
    }
  }

  return links.toSet().toList();
}