MCPcopy Index your code
hub / github.com/clips/pattern / _match

Function _match

pattern/text/search.py:81–101  ·  view source on GitHub ↗

Returns True if the pattern matches the given word string. The pattern can include a wildcard (*front, back*, *both*, in*side), or it can be a compiled regular expression.

(string, pattern)

Source from the content-addressed store, hash-verified

79regexp = type(re.compile(r"."))
80
81def _match(string, pattern):
82 """ Returns True if the pattern matches the given word string.
83 The pattern can include a wildcard (*front, back*, *both*, in*side),
84 or it can be a compiled regular expression.
85 """
86 p = pattern
87 try:
88 if p.startswith(WILDCARD) and (p.endswith(WILDCARD) and p[1:-1] in string or string.endswith(p[1:])):
89 return True
90 if p.endswith(WILDCARD) and not p.endswith("\\"+WILDCARD) and string.startswith(p[:-1]):
91 return True
92 if p == string:
93 return True
94 if WILDCARD in p[1:-1]:
95 p = p.split(WILDCARD)
96 return string.startswith(p[0]) and string.endswith(p[-1])
97 except AttributeError:
98 # For performance, calling isinstance() last is 10% faster for plain strings.
99 if isinstance(p, regexp):
100 return p.search(string) is not None
101 return False
102
103#--- LIST FUNCTIONS --------------------------------------------------------------------------------
104# Search patterns can contain optional constraints,

Callers 1

matchMethod · 0.85

Calls 2

splitMethod · 0.45
searchMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…