Pattern to extract text between parenthesis
问题 How to extract string from "(" and ")" using pattern matching or anything. For example if the text is ` "Hello (Java)" Then how to get only "Java" . Thanks. 回答1: Try this: String x= "Hello (Java)"; Matcher m = Pattern.compile("\\((.*?)\\)").matcher(x); while(m.find()) { System.out.println(m.group(1)); } or String str = "Hello (Java)"; String answer = str.substring(str.indexOf("(")+1,str.indexOf(")")); 回答2: List<String> matchList = new ArrayList<String>(); Pattern regex = Pattern.compile("\\((