我就廢話不多說,大家還是直接看代碼吧~
1
2
3
4
5
6
7
8
9
10
11
12
13
|
/*** * 英文 */ String abc1 = "百度科技(123)公司1" ; abc1 = abc1.replaceAll( "\\(|\\)" , "" ); System.out.println(abc1); /** * 中文 */ String abc2 = "百度科技(123)公司2" ; abc2 = abc2.replaceAll( "(" , "" ).replaceAll( ")" , "" ); System.out.println(abc2); |
補充知識:java用正則匹配中文中括號,和英文中括號
1
2
3
4
|
String regex = "(?<=\\[)(\\S+)(?=\\])|(?<=【)[^】]*" ; Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(sss.get(i)); while (matcher.find()) {matcher.get( 0 )} |
以上這篇java去除中文括號小括號,或者英文括號的實例代碼就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持服務(wù)器之家。
原文鏈接:https://blog.csdn.net/baidu_16217779/article/details/70907992