时间:2020-09-17 13:00:24 | 栏目: | 点击:次
我就废话不多说,大家还是直接看代码吧~
/***
* 英文
*/
String abc1 = "百度科技(123)公司1";
abc1 = abc1.replaceAll("\\(|\\)", "");
System.out.println(abc1);
/**
* 中文
*/
String abc2 = "百度科技(123)公司2";
abc2 = abc2.replaceAll("(","").replaceAll(")","");
System.out.println(abc2);
补充知识:java用正则匹配中文中括号,和英文中括号
String regex = "(?<=\\[)(\\S+)(?=\\])|(?<=【)[^】]*";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(sss.get(i));
while (matcher.find()) {matcher.get(0)}