MCPcopy
hub / github.com/msiemens/tinydb / matches

Method matches

tinydb/queries.py:332–347  ·  view source on GitHub ↗

Run a regex test against a dict value (whole string has to match). >>> Query().f1.matches(r'^\\w+$') :param regex: The regular expression to use for matching :param flags: regex flags to pass to ``re.match``

(self, regex: str, flags: int = 0)

Source from the content-addressed store, hash-verified

330 )
331
332 def matches(self, regex: str, flags: int = 0) -> QueryInstance:
333 """
334 Run a regex test against a dict value (whole string has to match).
335
336 >>> Query().f1.matches(r'^\\w+$')
337
338 :param regex: The regular expression to use for matching
339 :param flags: regex flags to pass to ``re.match``
340 """
341 def test(value):
342 if not isinstance(value, str):
343 return False
344
345 return re.match(regex, value, flags) is not None
346
347 return self._generate_test(test, ('matches', self._path, regex))
348
349 def search(self, regex: str, flags: int = 0) -> QueryInstance:
350 """

Callers 4

test_regexFunction · 0.80
test_anyFunction · 0.80
test_allFunction · 0.80
test_hasFunction · 0.80

Calls 1

_generate_testMethod · 0.95

Tested by 4

test_regexFunction · 0.64
test_anyFunction · 0.64
test_allFunction · 0.64
test_hasFunction · 0.64