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

 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         

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

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

相关文章:

  • 2022-02-07
  • 2022-12-23
  • 2021-11-29
  • 2021-11-20
  • 2022-12-23
  • 2022-12-23
  • 2021-08-27
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-02-07
  • 2021-08-27
  • 2022-12-23
  • 2022-02-07
相关资源
相似解决方案