Let $X$ be a ball Banach function space on ${mathbb R}^n$. In this article, under the mild assumption that the Hardy--Littlewood maximal operator is bounded on the associated space $X$ of $X$, the authors prove that, for any $fin C_{mathrm{c}}^2({mathbb R}^n)$, $$sup_{lambdain(0,infty)}lambdaleft |left|left{yin{mathbb R}^n: |f(cdot)-f(y)| >lambda|cdot-y|^{frac{n}{q}+1}right}right|^{frac{1}{q}} right|_Xsim | abla f|_X$$ with the positive equivalence constants independent of $f$, where $qin(0,infty)$ is an index depending on the space $X$, and $|E|$ denotes the Lebesgue measure of a measurable set $Esubset {mathbb R}^n$. Particularly, when $X:=L^p({mathbb R}^n)$ with $pin [1,infty)$, the above estimate holds true for any given $qin [1, p]$, which when $q=p$ is exactly the recent surprising formula of H. Brezis, J. Van Schaftingen, and P.-L. Yung, and which even when $q< p$ is new. This generalization has a wide range of applications and, particularly, enables the authors to establish new fractional Sobolev and Gagliardo--Nirenberg inequalities in various function spaces, including Morrey spaces, mixed-norm Lebesgue spaces, variable Lebesgue spaces, weighted Lebesgue spaces, Orlicz spaces, and Orlicz-slice (generalized amalgam) spaces, and, even in all these special cases, the obtained results are new. The proofs of these results strongly depend on the Poincare inequality, the extrapolation, the exact operator norm on $X$ of the Hardy--Littlewood maximal operator, and the geometry of $mathbb{R}^n.$