\(\dfrac{x^2+y^2-4+2xy}{x^2-y^2+4+4x}\)
\(=\dfrac{\left(x^2+2xy+y^2\right)-4}{\left(x^2+4x+4\right)-y^2}\)
\(=\dfrac{\left(x+y\right)^2-4}{\left(x+2\right)^2-y}\)
\(=\dfrac{\left(x+y-2\right)\left(x+y+2\right)}{\left(x+y+2\right)\left(x-y+2\right)}\)
\(=\dfrac{x+y-2}{x-y+2}\)