MCPcopy Create free account
hub / github.com/bytebase/dbhub / likePatternToRegex

Function likePatternToRegex

src/tools/search-objects.ts:60–68  ·  view source on GitHub ↗

* Convert SQL LIKE pattern to JavaScript regex * Supports % (any chars) and _ (single char)

(pattern: string)

Source from the content-addressed store, hash-verified

58 * Supports % (any chars) and _ (single char)
59 */
60function likePatternToRegex(pattern: string): RegExp {
61 // Escape special regex characters except % and _
62 const escaped = pattern
63 .replace(/[.*+?^${}()|[\]\\]/g, "\\$&")
64 .replace(/%/g, ".*")
65 .replace(/_/g, ".");
66
67 return new RegExp(`^${escaped}$`, "i");
68}
69
70/**
71 * Resolve the set of schemas a search should scope to when the caller did not

Callers 6

searchSchemasFunction · 0.85
searchTablesFunction · 0.85
searchViewsFunction · 0.85
searchColumnsFunction · 0.85
searchProceduresFunction · 0.85
searchIndexesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected