4. As shown in Figure 2,

Square $A B C D$ has a side length of $1, E$ is a point on the extension of $C B$, connect $E D$ intersecting $A B$ at $P$, and $P E$ $=\sqrt{3}$. Then the value of $B E-P B$ is $\qquad$
4.1.

Let $B E=x, P B=y$, then
$$
\left\{\begin{array}{l}
x^{2}+y^{2}=(\sqrt{3})^{2}, \\
\frac{y}{1}=\frac{x}{x+1} .
\end{array}\right.
$$

From (2), we have $x-y=x y$.
From (1) and (3), we have
$$
\begin{array}{l}
(x-y)^{2}+2(x-y)-3=0, \\
(x-y+3)(x-y-1)=0 .
\end{array}
$$

Clearly, $x>y, x-y+3>0$.
Therefore, $x-y-1=0, x-y=1$.
Thus, the value of $B E-P B$ is 1.