parseChannelId method Null safety

String? parseChannelId(
  1. String url
)

Parses a channel id from an url. Returns null if the username is not found.

Implementation

static String? parseChannelId(String url) {
  if (url.isEmpty) {
    return null;
  }

  if (validateChannelId(url)) {
    return url;
  }

  var regMatch = RegExp(r'youtube\..+?/channel/(.*?)(?:\?|&|/|$)')
      .firstMatch(url)
      ?.group(1);
  if (!regMatch.isNullOrWhiteSpace && validateChannelId(regMatch!)) {
    return regMatch;
  }
  return null;
}