matches static method
Verifica si un texto coincide con un patrón que puede contener wildcards (*)
Examples:
matches("hello.world", "hello.*")returnstruematches("api.example.com", "*.example.*")returnstruematches("test", "test")returnstruematches("testing", "test")returnsfalse
Implementation
static bool matches(String text, String pattern) {
if (pattern.isEmpty) return text.isEmpty;
if (text.isEmpty) return pattern == '*' || pattern.isEmpty;
// Si no hay wildcards, usar comparación directa
if (!pattern.contains('*')) {
return text.toLowerCase().contains(pattern.toLowerCase());
}
// Convertir el patrón a regex escapando caracteres especiales excepto *
final regexPattern = _convertWildcardToRegex(pattern);
try {
final regex = RegExp(regexPattern, caseSensitive: false);
return regex.hasMatch(text);
} catch (e) {
// Si hay error en el regex, fallback a comparación simple
return text.toLowerCase().contains(pattern.toLowerCase().replaceAll('*', ''));
}
}