getYoutubeId method

String? getYoutubeId()

Implementation

String? getYoutubeId() {
  if (contains("youtube") == false) {
    return null;
  }
  final RegExp regExp2 = RegExp(r"^.*(?:https?:\/\/)?(?:www\.)?youtu(?:\.be\/|be.com\/\S*(?:watch|embed)(?:(?:(?=\/[-a-zA-Z0-9_]{11,}(?!\S))\/)|(?:\S*v=|v\/)))([-a-zA-Z0-9_]{11,}).*");
  final match = regExp2.firstMatch(this);
  final result = match != null ? match.group(1) ?? "" : "";
  if (result.isNotEmpty) {
    return result;
  }
  return null;
}