Replace an ``old`` subset of ``text`` with ``new``.
    
    ``old`` type may be either a string or regular expression.
    
    If ``strip``, remove all leading/trailing whitespace.
    
    If ``count``, replace the specified number of occurence, otherwise replace all.

def replace(text, old, new, count=None, strip=False):
    '''
    Replace an ``old`` subset of ``text`` with ``new``.
    
    ``old`` type may be either a string or regular expression.
    
    If ``strip``, remove all leading/trailing whitespace.
    
    If ``count``, replace the specified number of occurence, otherwise replace all.
    '''
    if is_string(old):
        text = text.replace(old, new, -1 if count is None else count)
    else:
        text = old.sub(new, text, 0 if count is None else count)
    
    if strip:
        text = text.strip(None if strip == True else strip)
    
    return text