(pattern string)
| 193 | } |
| 194 | |
| 195 | func convertToRegexp(pattern string) string { |
| 196 | // 转义正则特殊字符 |
| 197 | re := regexp.MustCompile(`([\[\]\(\)\{\}\^\$\.\+])`) |
| 198 | pattern = re.ReplaceAllString(pattern, `\$1`) |
| 199 | |
| 200 | // 将 * 和 ? 转换为对应的正则表达式 |
| 201 | pattern = strings.ReplaceAll(pattern, "*", ".*") |
| 202 | pattern = strings.ReplaceAll(pattern, "?", ".") |
| 203 | |
| 204 | return "^" + pattern + "$" // 添加 ^ 和 $ 以确保完全匹配 |
| 205 | } |