import re


def alter_parameter_formula(parameter, old, new):
    """ Replace the `old` part with `new` in the formula field and return
    the parameter itself.
    """
    if hasattr(parameter, "formula"):
        parameter.formula = re.sub(r"\b{}\b".format(old), new, parameter.formula)
    return parameter