Ok, so, I have an exercise to build a sort of a java compiler. I won't get too much in details.
Basically, I want to know if it's possible to use a regex that can identify a closing bracket.
for example, this would be a legal input

```
void foo(){
   asd
}

```

and this won't be

```
void foo(){
   asd
   if (){
      asd
   }

```

as you can see, there is only 1 closer (}) for 2 openers ({), making it invalid input. is there any way to use a regex and identify that the number of appearances matches?