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