利用正则表达式提取括号内内容

比如现在要提取  中华人们共和国,简称(中国) 这句话中括号里的“中国”

 1 import java.util.regex.Matcher;
 2 import java.util.regex.Pattern;
 3 public class  Test
 4 {
 5     public static void main(String[] args)
 6     {
 7         String str ="中华人民共和国,简称(中国)。";
 8         Matcher mat = Pattern.compile("(?<=\()(\S+)(?=\))").matcher(str);//此处是中文输入的()
 9         while(mat.find()){
10             System.out.println(mat.group());
11         }
12     }
13 }
14         

最后附一下用到的零宽断言:

原文地址:https://www.cnblogs.com/manliu/p/4004696.html