我正在尝试提取分隔符内的字符串出现(在这种情况下是括号),但不是引号内的字符串(单引号或双引号)。这是我尝试过的 - 这个正则表达式获取括号内的所有出现,以及引号内的那些(我不想要引号内的那些)
public class RegexMain {
static final String PATTERN = "\\(([^)]+)\\)";
static final Pattern CONTENT = Pattern.compile(PATTERN);
/**
* @param args
*/
public static void main(String[] args) {
String testString = "Rhyme (Jack) and (Jill) went up the hill on \"(Peter's)\" request.";
Matcher match = CONTENT.matcher(testString);
while(match.find()) {
System.out.println(match.group()); // prints Jack, Jill and Peter's
}
}
}