$\mu$ measurable functions and separable metric spaces

I was reading a math textbook and the author gives the following without proof. I have no clue on how to proceed.

Let $(X, \mathcal{F}, \mu)$ be a measure space and $(Y,d)$ be a separable metric space ($d$ is the metric). If $f:(X,\mathcal{F}) \rightarrow (Y, d)$ is a $\mu$-measurable function prove that there exists an $\mathcal{F}$ measurable function which coincides with $f$ everywhere except on a $\mu$-negligible set.

Any help is greatly appreciated.

EDIT: The textbook is “Functions of Bounded Variation and Free Discontinuity Problems” by Luigi Ambrosio et. al.

Solutions Collecting From Web of "$\mu$ measurable functions and separable metric spaces"

Edit: I have just figured a much easier way.
So, I edited the answer.


Let $\mathcal{V} = \{V_n : n = 1, 2, \dotsc\}$
be a countable base for the topology of $Y$.

For each $V_n$, choose a negligible $E_n \subset X$ such that
$f^{-1}(V_n) \setminus E_n \in \mathcal{F}$.
It may happen that $\bigcup E_n \not \in \mathcal{F}$.
But since it is a negligible set, there is a negligible
$Z \in \mathcal{F}$ such that $\bigcup E_n \subset Z$.

Fix some $y \in Y$,
and then define
$$
g(x)
=
\left\{
\begin{array}{}
f(x), & x \not \in Z
\\
y, & x \in Z
\end{array}
\right.
$$

Notice that for any $V_n \in \mathcal{V}$,
if $y \not \in V_n$,
$$
\begin{align*}
g^{-1}(V_n)
&=
f^{-1}(V_n) \setminus Z
\\&=
(f^{-1}(V_n) \setminus E_n) \setminus Z
\in \mathcal{F}.
\end{align*}
$$
And if $y \in V_n$,
$$
\begin{align*}
g^{-1}(V_n)
&=
f^{-1}(V_n) \cup Z
\\&=
(f^{-1}(V_n) \setminus E_n) \cup Z
\in \mathcal{F}.
\end{align*}
$$
That is, $g^{-1}(\mathcal{V}) \subset \mathcal{F}$.
All open sets of $Y$ are (countable) union of elements in $\mathcal{V}$.
Therefore, $\mathcal{V}$ generates the $\sigma$-algebra of Borel sets
$\mathcal{B}$.
And so, $g$ is $\mathcal{F}$-measurable.
In fact,
$$
g^{-1}(\mathcal{B})
=
g^{-1}(\sigma(\mathcal{V}))
=
\sigma \left(g^{-1}(\mathcal{V})\right)
\subset \mathcal{F}.
$$

Since it is evident that $g$ and $f$ are equal almost everywhere,
the proof is complete.

Let $(V_n) \in Y$ be a countable base for the separable metric space $Y$. Then define
$V_n^\prime = V_n \cap V_{n-1}^c \cap V_{n-2}^c… \cap V_1^c$ and $V_1^\prime = V_1$. Clearly, $V_n^\prime$ are all
measurable. Now $f^{-1}(V_n^\prime) = E_n \cup N_n = E_n + (E_n^c \cap N_n) = E_n + N_n^\prime$, where $E_n$ is
$\mathcal{F}$-measurable and $N_n, N_n^\prime$ are
$\mu$-negligible. As all $V_n^\prime$ are all pairwise disjoint, $f^{-1}(V_n^\prime) = E_n + N_n^\prime$ are all disjoint.
Define a new function $g: X \rightarrow Y$ such that $g(x) = f(x)$ on all $x \in E_n$ and on $x \in (\cup_{i=0}^\infty E_i)^c$ to be any
value. Then $g$ is $\mathcal{F}$-measurable and is a.e. equal to $f$.

I hope this proof is correct.