I am studying for an exam of algebraic geometry, and I would like to know if the following is correct.
Let $X$ be an affine variety, and let $\mathcal{O}_{X}$ denote its sheaf of regular functions. Let $S\subset X$ be a closed subset. I would like to find the ring of regular functions on $X-S$.
Assume that $X-S$ can be covered by opens subsets of $X$ contained in $X-S$, $X-S=\bigcup_iU_i$. Then the map of sheafs $\phi:\mathcal{O}_{X-S}\to\mathcal{O}_{X}$ induced by inclusion gives isomorphisms $\mathcal{O}_{X-S}(U_i)\cong\mathcal{O}_{X}(U_i)$ (in fact it is the identity map). Now we have: $$\mathcal{O}_{X-S}(X-S)=\varprojlim_i\mathcal{O}_{X-S}(U_i)\cong\varprojlim_i\mathcal{O}_{X}(U_i)$$ Now we can always choose a cover by basic opens of the form $D(f)=\{x\in X|f(x)\neq0\}$, so let $U_i=D(f_i)$. Then $\mathcal{O}_{X}(D(f_i))=A(X)_{f_i}$, and we can look at it as a subring of the quotient field $K(X)$. Then: $$\varprojlim_i\mathcal{O}_{X}(U_i)=\bigcap_iA(X)_{f_i}$$ and thus we see that the ring of regular functions on $X-S$ is given by inverting all elements of $A(X)$ whose zero-set is completely contained in $S$.
Please, tell me if I committed any mistakes, or if some steps are too vague.