isHostMatchesRegexPattern static method

bool isHostMatchesRegexPattern(
  1. String url,
  2. List<String> patterns
)

Implementation

static bool isHostMatchesRegexPattern(String url, List<String> patterns) {
  try {
    final uri = Uri.parse(url);
    final host = uri.host;

    for (final pattern in patterns) {
      if (pattern.contains('*')) {
        // Simple wildcard matching
        final regexPattern = pattern.replaceAll('*', '.*');
        final regex = RegExp(regexPattern);
        if (regex.hasMatch(host)) {
          return true;
        }
      } else if (host == pattern) {
        return true;
      }
    }
    return false;
  } catch (e) {
    return false;
  }
}