getYouTubeUrl static method

String getYouTubeUrl(
  1. String text
)

Implementation

static String getYouTubeUrl(String text) {
  RegExp regExp = RegExp(
      r'((?:https?:)?\/\/)?((?:www|m)\.)?((?:youtube\.com|youtu.be))(\/(?:[\w\-]+\?v=|embed\/|v\/)?)([\w\-]+)(\S+)?'
  );

  String? matches = regExp.stringMatch(text);
  if (matches == null) return ''; /// Always returns here while the video URL is in the content parameter

  final String youTubeUrl = matches;
  return youTubeUrl;
}