MCPcopy Index your code
hub / github.com/microsoft/playwright-python / glob_to_regex_pattern

Function glob_to_regex_pattern

playwright/_impl/_glob.py:19–65  ·  view source on GitHub ↗
(glob: str)

Source from the content-addressed store, hash-verified

17
18
19def glob_to_regex_pattern(glob: str) -> str:
20 tokens = ["^"]
21 in_group = False
22
23 i = 0
24 while i < len(glob):
25 c = glob[i]
26 if c == "\\" and i + 1 < len(glob):
27 char = glob[i + 1]
28 tokens.append("\\" + char if char in escaped_chars else char)
29 i += 1
30 elif c == "*":
31 char_before = glob[i - 1] if i > 0 else None
32 star_count = 1
33 while i + 1 < len(glob) and glob[i + 1] == "*":
34 star_count += 1
35 i += 1
36 if star_count > 1:
37 char_after = glob[i + 1] if i + 1 < len(glob) else None
38 if char_after == "/":
39 if char_before == "/":
40 tokens.append("((.+/)|)")
41 else:
42 tokens.append("(.*/)")
43 i += 1
44 else:
45 tokens.append("(.*)")
46 else:
47 tokens.append("([^/]*)")
48 else:
49 if c == "{":
50 in_group = True
51 tokens.append("(")
52 elif c == "}":
53 in_group = False
54 tokens.append(")")
55 elif c == ",":
56 if in_group:
57 tokens.append("|")
58 else:
59 tokens.append("\\" + c)
60 else:
61 tokens.append("\\" + c if c in escaped_chars else c)
62 i += 1
63
64 tokens.append("$")
65 return "".join(tokens)

Callers 2

glob_to_regexFunction · 0.90

Calls 1

appendMethod · 0.80

Tested by 1

glob_to_regexFunction · 0.72