MCPcopy Create free account
hub / github.com/Noumena-Network/code / urlPatternToRegex

Function urlPatternToRegex

src/services/mcp/config.ts:321–327  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

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

Callers 1

urlMatchesPatternFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected