Regex (Perl / Java / PCRE / .NET), 42 bytes
^(((\3xx|^x)+\3x|)x)(?=(\1*)\2+$)\1*$\4|^$
Try it online! - Perl
Try it online! - Java
Try it online! - PCRE
Try it online! - .NET
This uses the equivalent of ^(\1xx|^x)*$
to match a perfect square (using a nested backreference), and then uses a square-testing algorithm which works thanks to the Chinese remainder theorem (which only requires ECMAScript or better), to assert that the captured perfect square is the square root of the inputted number. The latter algorithm is explained in this post, and this exact square-testing regex is used in the second answer in this post.
If it did not need to match \$0^4\$, the regex would be 39 bytes, tying with primo's excellent solution. There's a lot of overhead for capturing \$1\$ less than a perfect square as the first step, which is required for the ECMAScript perfect square regex.
^ # tail = N = input number
( # \1 = the largest perfect square for which the subsequent
# expression matches
( # \2 = \1 - 1
(\3xx|^x)+ # head = some positive perfect square A^2
\3x # head = (A+1)^2-1
|
# or head = 0; this allows us to get \1 = 1^2
)
x # head += 1
)
# Assert that N == \1^2
(?=
(\1*)\2+$ # iff \1*\1 == N, then the first match here must result in \3==0
)
\1*$\4 # assert \1 divides N-\1, and \4==0
|
^$ # Allow us to match N=0, which can't be matched above
Alternative 42 bytes:
(((\3xx|^x)+\3x)x)(?=(\1*)\2+$)\1*$\4|^x?$
Try it online! - Perl
Try it online! - Java
Try it online! - PCRE
Try it online! - .NET
The main expression here only matches fourth powers of \$2^4\$ or greater, leaving the work of matching both \$1\$ and \$0\$ to the alternative at the end. If it only needed to match the former, it would be 37 bytes.