Check whether the regular expression `regexp` matches the string representation of the exception using :func:`python:re.search`. If it matches `True` is returned, otherwise an `AssertionError` is raised.
(self, regexp: str | re.Pattern[str])
| 774 | return fmt.repr_excinfo(self) |
| 775 | |
| 776 | def match(self, regexp: str | re.Pattern[str]) -> Literal[True]: |
| 777 | """Check whether the regular expression `regexp` matches the string |
| 778 | representation of the exception using :func:`python:re.search`. |
| 779 | |
| 780 | If it matches `True` is returned, otherwise an `AssertionError` is raised. |
| 781 | """ |
| 782 | __tracebackhide__ = True |
| 783 | value = stringify_exception(self.value) |
| 784 | msg = ( |
| 785 | f"Regex pattern did not match.\n" |
| 786 | f" Expected regex: {regexp!r}\n" |
| 787 | f" Actual message: {value!r}" |
| 788 | ) |
| 789 | if regexp == value: |
| 790 | msg += "\n Did you mean to `re.escape()` the regex?" |
| 791 | assert re.search(regexp, value), msg |
| 792 | # Return True to allow for "assert excinfo.match()". |
| 793 | return True |
| 794 | |
| 795 | def _group_contains( |
| 796 | self, |