@gvegayon Isn't that just the brackets enumeration problem? I think it's well-studied and well-known. Try a search for "balanced parentheses" or similar and see if it gives you what you need.
@rastinza Have you seen Iris AI? They claim to do exactly that.
I have no affiliation with them, but they appear to do what you are asking.
@solarchemist What do you get with en_GB.utf-8 and en_UK.utf-8 ?? I don't know what command you are running after setting the locale.
(Note: I suspect it won't work, but thought I'd ask in case someone else wonders the same thing)