",怎么用正则表达式匹配中括号内的数组,p

,打扰一下,",怎么用正则表达式匹配中括号内的数组,p
最新回答
浅色夏沫

2025-06-19 08:35:56

public static void main(String[] args) { String content = "(hello)"; String regex = "(?<=\\().*(?=\\))"; Pattern p = Pattern.compile(regex); Matcher m = p.matcher(content); while (m.find()) { System.out.println(m.group()); } }
public static void main(String[] args) { String content = "(hello)"; String regex = "[^()]+"; Pattern p = Pattern.compile(regex); Matcher m = p.matcher(content); while (m.find()) { System.out.println(m.group()); } }