x2+4xy-x+3y2+y-2=(x+3y-2)(x+y+1)
METHOD
Assume we can write the factors as:
(x+ay+b)(x+cy+d)=x2+cxy+dx+axy+acy2+ady+bx+bcy+bd, where a, b, c, d are constants. We have to find these constants.
Equate coefficients:
constant: bd=-2, d=-2/b;
x: b+d=-1, d=-(b+1); (4)
y: ad+bc=1; d=(1-bc)/a (3)
xy: a+c=4, c=4-a; (1)
y2: ac=3, c=3/a; (2)
Therefore from (1) and (2), c=4-a=3/a, so 4a-a2=3, a2-4a+3=0=(a-1)(a-3), so a=1 or 3⇒c=3 or 1 respectively.
Also, from (3) and (4), d=-b-1=1-3b⇒b=1, d=-2 when a=1 and c=3; or d=-b-1=(1-b)/3, -3b-3=1-b⇒b=-2, d=1 when a=3 and c=1.
Therefore we have (a,b,c,d)=(1,1,3,-2) or (3,-2,1,1). But these yield the same factors x+y+1 and x+3y-2, hence:
x2+4xy-x+3y2+y-2=(x+3y-2)(x+y+1).