<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def assert_raises_regex(exception, regex, msg_fmt="{msg}"):
 """Fail unless an exception with a message that matches a regular expression is raised within the context. The regular expression can be a regular expression string or object. Traceback (most recent call last):
 AssertionError: 'Generic Error' does not match '\\\\d+' The following msg_fmt arguments are supported: * msg - the default error message * exc_type - exception type that is expected * exc_name - expected exception type name * text - actual error text * pattern - expected error message as regular expression string """


    def test(exc):
        compiled = re.compile(regex)
        if not exc.args:
            msg = "{} without message".format(exception.__name__)
            fail(
                msg_fmt.format(
                    msg=msg,
                    text=None,
                    pattern=compiled.pattern,
                    exc_type=exception,
                    exc_name=exception.__name__,
                )
            )
        text = exc.args[0]
        if not compiled.search(text):
            msg = "{!r} does not match {!r}".format(text, compiled.pattern)
            fail(
                msg_fmt.format(
                    msg=msg,
                    text=text,
                    pattern=compiled.pattern,
                    exc_type=exception,
                    exc_name=exception.__name__,
                )
            )

    context = AssertRaisesRegexContext(exception, regex, msg_fmt)
    context.add_test(test)
    return context