Test if a string is parenthesly balanced We call a parens group the open paren (, its matching close paren ) and everything inside them.
A parens group or string is called parenthesly balanced if it contains either nothing or only 2 parenthesly balanced parens groups.
For example:
The string   &quot;(()())()&quot;      is parenthesly balanced
              (    )()       Because it contains exactly 2 parenthesly balanced parens groups
               ()()          The left one is parenthesly balanced because it contains 2 parenthesly balanced parens groups (balanced because they are empty). The right one is parenthesly balanced because it contains nothing.

Likewise:
The string   &quot;(()(()))()&quot;    is not parenthesly balanced
              (      )()     Because it contains a parens group that is not parenthesly balanced: the left one
               ()(  )        The left one is not balanced because it contains a parens group that is not balanced: the right one
                  ()         The right one is not balanced because it only contains one balanced group.

So, a parenthesly balanced string or parens group should either:

Contain nothing at all.
Or contain only and exactly 2 parenthesly balanced parens groups. It should contain nothing else.

Task:
Your task is to write a function or program that checks if a given string is a parenthesly balanced one or not.
Input:
Input will be a string or list of characters or something similar. You can assume that the string will only consist of the characters '(' and ')'. You can also assume that each open paren ( will have its matching close paren ), so don't worry about strings like &quot;(((&quot; or &quot;)(&quot; or &quot;(())(&quot;...
Note: As mentioned by @DigitalTrauma in his comment bellow, it's ok to subtitute the () combo by other characters (such as &lt;&gt;, [], ...), if it's causing additional work like escaping in some languages
Output:
Anything to signal whether the string is parenthesly balanced or not (true or false, 1 or 0, ...). Please include in your answer what your function/program is expected to yield.
Examples:
&quot;&quot;                                        =&gt; True
&quot;()()&quot;                                    =&gt; True
&quot;()(()())&quot;                                =&gt; True
&quot;(()(()(()())))(()())&quot;                    =&gt; True
&quot;(((((((()())())())())())())())()&quot;        =&gt; True
&quot;()&quot;                                      =&gt; False
&quot;()()()&quot;                                  =&gt; False
&quot;(())()&quot;                                  =&gt; False
&quot;()(()(())())&quot;                            =&gt; False
&quot;(()())(((((()())()))())())&quot;              =&gt; False
&quot;()(()()()())&quot;                            =&gt; False
&quot;()(()(()())()())&quot;                        =&gt; False

The last two examples really made a difference!
Best of luck!
Japt v2, 20 bytes

V="()"V¥iU1 eViV²1 V


Test it online!

Everyone misunderstood the challenge at first and though that each pair of parentheses had to contain an even number of sub-pairs, when in fact the challenge actually asks for 0 or 2 sub-pairs. So here's my revised answer, using the same technique as before.

We can still solve the challenge with recursive replacement. The thing is, instead of just removing all occurrences of ()(), we need to make sure that there's nothing else in the same wrapper besides the ()() (in other words, no ()()()() or anything like that). We can do this by recursively replacing (()()) with ().

The new problem is that the input itself does not have one pair of outer parentheses (as that would make it not a parenthesly balanced string), forcing us to wrap it in an extra pair to fully reduce it. Finally, the end result for balanced strings is now () instead of the empty string, so we check for equality rather than just taking logical NOT of the output.