feat: AV/BV号直接跳转

This commit is contained in:
guozhigq
2023-08-07 21:50:41 +08:00
parent 8aac1dd714
commit 1c08edb113
2 changed files with 47 additions and 0 deletions

View File

@ -46,4 +46,28 @@ class IdUtils {
}
return (r - ADD) ^ XOR;
}
// 匹配
static Map matchAvorBv({String? input}) {
Map result = {};
if (input == null || input == '') {
return result;
}
RegExp bvRegex = RegExp(r'BV[0-9A-Za-z]{10}', caseSensitive: false);
RegExp avRegex = RegExp(r'AV\d+', caseSensitive: false);
Iterable<Match> bvMatches = bvRegex.allMatches(input);
Iterable<Match> avMatches = avRegex.allMatches(input);
List<String> bvs = bvMatches.map((match) => match.group(0)!).toList();
List<String> avs = avMatches.map((match) => match.group(0)!).toList();
if (bvs.isNotEmpty) {
result['BV'] = bvs[0].substring(0, 2).toUpperCase() + bvs[0].substring(2);
}
if (avs.isNotEmpty) {
result['AV'] = avs[0].substring(2);
}
return result;
}
}