Construct a PauliTerm from the result of str(pauli_term)

def from_compact_str(cls, str_pauli_term):
        """Construct a PauliTerm from the result of str(pauli_term)
        """
        coef_str, str_pauli_term = str_pauli_term.split('*')
        try:
            coef = int(coef_str)
        except ValueError:
            try:
                coef = float(coef_str)
            except ValueError:
                coef = complex(coef_str)

        op = sI() * coef
        if str_pauli_term == 'I':
            return op
        ma = re.fullmatch(r'(([XYZ])(\d+))+', str_pauli_term)
        if ma is None:
            raise ValueError(f"Could not parse pauli string {str_pauli_term}")
        for ma in re.finditer(r'([XYZ])(\d+)', str_pauli_term):
            op *= cls(ma.group(1), int(ma.group(2)))

        return op