In this paper we characterize global regularity in the sense of Shubin of twisted partial differential operators of second order in dimension $2$. These operators form a class containing the twisted Laplacian, and in bi-unique correspondence with second order ordinary differential operators with polynomial coefficients and symbol of degree $2$. This correspondence is established by a transformation of Wigner type. In this way the global regularity of twisted partial differential operators turns out to be equivalent to global regularity and injectivity of the corresponding ordinary differential operators, which can be completely characterized in terms of the asymptotic behavior of the Weyl symbol. In conclusion we observe that we have obtained a new class of globally regular partial differential operators which is disjoint from the class of hypo-elliptic operators in the sense of Shubin.