def cformat2regex(flags, width, precision, length, specifier):
    """Get regex substring that will match the given cformat components.

    Args:
        flags (str): Format flags.
        width (str): Minimum field width.
        precision (str): Field precision.
        length (str): Field value size (e.g. short, long).
        specifier (str): Field specifier.

    Returns:
        str: Regex expression that will match the provided components.

    """
    pat_dec = '[-+]?\\d+(?:\\.\\d+)?'
    pat_sub = ''
    pad_zero = 0
    if '0' in flags:
        if '+' in flags:
            pat_sub += '[-+]'
        if width and specifier in 'diueEfgGoxX':
            pad_zero = int(width)
    else:
        if '-' not in flags and width and specifier != 's':
            pat_sub += '\\s{,%s}' % width
        if '+' in flags:
            pat_sub += '[-+]'
    if precision and specifier in 'diuoxX':
        pad_zero = max(pad_zero, int(precision[1:]))
    if pad_zero and specifier in 'diueEfgG':
        pat_sub += '0{,%d}' % pad_zero
    if specifier == 'f':
        pat_sub += pat_dec
    elif specifier in 'eE':
        pat_sub += '%s%s[+-]\\d+' % (pat_dec, specifier)
    elif specifier in 'gG':
        pat_sub += '%s(?:[eE][+-]\\d+)?' % pat_dec
    elif specifier in 'diu':
        pat_sub += '\\d+'
    elif specifier in 'cs':
        if not width:
            if specifier == 'c':
                pat_sub += '.'
            else:
                pat_sub += '\\S+'
        else:
            pat_sub += '.{%s}' % width
    elif specifier in 'xX':
        if '#' in flags:
            pat_sub += '0%s' % specifier
        if pad_zero:
            pat_sub += '0{,%d}' % pad_zero
        pat_sub += '[\\dA-Za-f]+'
    elif specifier == 'o':
        if '#' in flags:
            pat_sub += '0'
        if pad_zero:
            pat_sub += '0{,%d}' % pad_zero
        pat_sub += '[0-7]*'
    if '-' in flags and '0' not in flags and width:
        pat_sub += '\\s{,%s}' % width
    return pat_sub
