I\'m trying to extract a string from round brackets. Let\'s say, I have John Doe (123456789) and I want to output the string 123456789 only.
John Doe (123456789)
123456789
You need to escape brackets in your regexp:
String in = "John Doe (123456789)"; Pattern p = Pattern.compile("\\((\\d*)\\)"); Matcher m = p.matcher(in); while (m.find()) { System.out.println(m.group(1)); }