This is an exercise of Gathmann's Algebraic Geometry.
Show that the regular functions on an open subset $U$ of an affine variety $X$ are the polynomials on $A(X)$, if $A(X)$ is a UFD and $U$ is the complement of an irreducible subvariety of codimension at least 2 in $X$.
There was an example showing that regular functions on $U=A^2\backslash\{0\}$ are polynomials. I am trying to use the same idea in that example.
Let $V\subsetneq V_0 \subsetneq V_1 \subset X$ be a chain of irreducible varieties.
Let $\phi$ be a regular function on $U$.
My idea is: if we can find two irreducible functions $f_1, f_2$ such that $V\subsetneq V(f_1), V\subsetneq V(f_2)$, then
$\phi=\frac{g_1}{f_1^n}$ on $D(f_1)$ and $\phi=\frac{g_2}{f_2^m}$ for some $g_1,g_2\in A(X)$ and $m,n\in N$.
($D(f)$ here means the distinguished open subset of $f$ in $X$, i.e., the set where $f$ is not equal to $0$ in $X$.)
Suppose $f_1$ does not divide $g_1$, $f_2$ does not divide $g_2$.
Then on $D(f_1)\cap D(f_2)$, we have $g_1f_2^m=g_2f_1^n$. Since $V(g_1f_2^m-g_2f_1^n)$ is closed, we also have $g_1f_2^m=g_2f_1^n$ on the closure of ${D(f_1)\cap D(f_2)}$ which is $X$. Then because of the irreducibility of $f_1,f_2$ and $A(X)$ is a UFD, we can prove that $m=n=0$. That proves that $\phi$ is a polynomial.
Sorry for the long post.
I'm not sure whether this is on the right track. Also I don't know how to show that I can find the irreducible $f_1, f_2$. Or they are probably not really irreducible, but product of linear factors. But how to state that in the proof? Any help would be appreciated!