java - Regex removing contents inside last bracket -


i have input text such as:

text (some other text) (more text) 

what i'm trying remove last brackets text inside it. ie (more text)
in more general terms, want expression match last bracket , contents.

i have tested quite few variations of following regex \s\(.*?\)$ cannot seem working, can tell . operator matching first bracket way through last closing bracket whatever i've tried can't seem think of how approach this.

i'm using java implementation of regex. (omitting escape character in above)

public static void main(string[] args){          string reg = "\\s\\([^)]+\\)$";         string text = "text (some other text) (more text)";         system.out.println(text.replaceall(reg, "")); } 

output :

text (some other text) 

edit : if have text after last brackets, @anubhava provided solution


Comments