getInstagramLink static method

String getInstagramLink(
  1. String? content
)

Implementation

static String getInstagramLink(String? content) {
  final regExp = RegExp(
    'instagram.com/(p|reel)/?[a-zA-Z0-9_-]+',
    multiLine: true,
    caseSensitive: false,
  );

  String? instagramUrl;

  try {
    final matches = regExp.allMatches(content!);
    if (matches.isNotEmpty) {
      instagramUrl = matches.first.group(0) ?? '';
    }
    // ignore: empty_catches
  } catch (error) {
    return '';
  }

  return instagramUrl != null ? 'https://$instagramUrl/embed' : '';
}