* Convert a URL pattern with wildcards to a RegExp * Supports * as wildcard matching any characters * Examples: * "https://example.com/*" matches "https://example.com/api/v1" * "https://*.example.com/*" matches "https://api.example.com/path" * "https://example.com:*\/*" matches any port
(pattern: string)
| 318 | * "https://example.com:*\/*" matches any port |
| 319 | */ |
| 320 | function urlPatternToRegex(pattern: string): RegExp { |
| 321 | // Escape regex special characters except * |
| 322 | const escaped = pattern.replace(/[.+?^${}()|[\]\\]/g, '\\$&') |
| 323 | // Replace * with regex equivalent (match any characters) |
| 324 | const regexStr = escaped.replace(/\*/g, '.*') |
| 325 | return new RegExp(`^${regexStr}$`) |
| 326 | } |
| 327 | |
| 328 | /** |
| 329 | * Check if a URL matches a pattern with wildcard support |