A lone *
is called a greedy operator, because it will try to match as much of the source as possible: in your case, up to the second }
.
You can use the lazy operator *?
, which will match as short as possible, here up to the first }
.
Like such:
/({.*?};)/
Or you can use a character set, noted with square brackets, that excludes the closing bracket: [^}]
(the ^
negates the content of the set) instead of the dot:
/({[^}]*};)/
(I personnally prefer this solution because it is more explicit as to which characters are allowed/restricted from the match, but in your case it's a simple matter of taste).
Your suggestion of adding a ?
after the semicolon is not relevant because it will only apply to the semicolon, not the whole group.