Task is to check if given string contains balanced sets of {}, [] and ().
For example, check(\"{[}]\") must return
Your solution seems overcomplicated and I have to admit that I didn't try too hard to understand it but it is not obvious to me that it is even correct. A very simple solution to this problem is to create a stack and go through the string pushing opening parentheses to the stack and popping from the stack on closing parentheses (when you pop you have to check that the opening and closing parentheses match).
It is unfortunately impossible to solve this problem with regular expressions as the language of well balanced parentheses is not regular.