当前位置:主页 > >

java去除中文括号小括号,或者英文括号的实例代码

时间: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)}

您可能感兴趣的文章:

相关文章