$g$ for each $P \in {{\mathscr{P}}}$ and $f$ (resp. $g$) defines $C$ (resp. $E$) at each $P \in {{\mathscr{P}}}\cap C$ (resp. $P \in {{\mathscr{P}}}\cap E$).

Let $R$ be the semi-local ring at all $P \in
  {{\mathscr{P}}}$. Since $R$ is a unique factorisation domain, there exist $f_1, g_1 \in R$ such that div$_{Spec(R)}(f_1) = C\mid _ {Spec(R)}$ and div$_{Spec(R)}(g_1) = E\mid _ {Spec(R)}$. For each $P \in {{\mathscr{P}}}$, let $m_P$ be the maximal ideal of the local ring $R_P$ at $P$. Then for each $P \in C\cap E \cap {{\mathscr{P}}}$, $m_P = (f_1, g_1)$. Let $P \in {{\mathscr{P}}}$. Suppose $P \not\in C$. Then $P \in E$. Since $E$ is regular on ${{\mathscr{X}}}$, by the choice of $g_1$, there exists $\theta_P \in m_P$ such that $m_P = (\theta_P, g_1)$. By the Chinese remainder theorem, there exists $\pi_P \in m_P$ such that $\pi_P
 \not\in m_Q$ for all $Q \in {{\mathscr{P}}}$, $Q \neq P$ and $\pi_p = \theta_P$ module $m_P^2$. Then $m_P = (\pi_P, g_1)$. Similarly for each $P \not\in E$, choose $\delta_P 
 \in m_P$ such that $m_P = (f_1, \delta_P)$ and $\delta_P \not\in m_Q$ for all $Q \in {{\mathscr{P}}}$, $Q \neq P$. Let $$f_2  =   \prod_{P \in {{\mathscr{P}}}\setminus C} \pi_P, ~~f = f_1f_2$$ 