Let $X$ be a Noetherian integral affine scheme. Let $U\subset X$ be an open subscheme whose complement has irreducible components of codimension $1$. Is $U$ affine? 


Some remarks:


* By EGA 4, Cor. 21.12.7, the complement of a codimension 2 closed subset is not affine.
* if $X$ is the spectrum of a UFD, then I believe this can not happen. The ideal defining the complement has height 1. Thus the radical has height 1, so it is an intersection of prime ideals of height 1 so it is principal.
* if $X$ is of Krull dimension 1 (e.g. Dedekind domain), this can [not](https://stacks.math.columbia.edu/tag/09N9) happen.



Complement of codimension 1 subset of affine scheme not affine
Quoting from [a paper](https://arxiv.org/abs/math/0406384) by Roth and Vakil ($\mathrm{cd}$ stands for cohomological dimension):



> 
> Let $S$ be $\mathbb{P}^2$ blown up at a point, and let $X$ be the
>  affine cone over some projective embedding of $S$. Let $Z\subset X$ be
>  the affine cone over the exceptional divisor of the blowup. Then $Z$
>  is of codimension one in $X$, but $\mathrm{cd}(X\backslash Z) = 1$, so
>  in particular it is not affine. This shows that, conversely, the
>  complement of a Weil divisor in an affine scheme need not be affine...
> 
> 
> 


Note that the complement of an effective Cartier divisor in an irreducible affine scheme *is* affine so if in addition to the assumptions in the question the ambient scheme is factorial ([e.g. regular](https://justinsmath.wordpress.com/2014/09/23/regular-implies-locally-factorial/)), then the complement of any pure codimension 1 closed subset is affine. 


