def regex(pattern, prompt=None, empty=False, flags=<NUM_LIT:0>):
s = _prompt_input(prompt)<EOL>if empty and not s:<EOL><INDENT>return None<EOL><DEDENT>else:<EOL><INDENT>m = re.match(pattern, s, flags=flags)<EOL>if m:<EOL><INDENT>return m<EOL><DEDENT>else:<EOL><INDENT>return regex(pattern, prompt=prompt, empty=empty, flags=flags)<EOL><DEDENT><DEDENT>
Prompt a string that matches a regular expression.

    Parameters
    ----------
    pattern : str
        A regular expression that must be matched.
    prompt : str, optional
        Use an alternative prompt.
    empty : bool, optional
        Allow an empty response.
    flags : int, optional
        Flags that will be passed to ``re.match``.

    Returns
    -------
    Match or None
        A match object if the user entered a matching string.
        None if the user pressed only Enter and ``empty`` was True.

    See Also
    --------
    re.match