import java.util.ArrayList; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; /** * @Author: yangyubing * @Description: * @Date: 11:11 2019/12/9 */ public class Test { public static void main(String[] args) { String str = "张三(zhangsan),李四(lisi)"; System.out.println(clearBracket(str)); String msg = "PerformanceManager[第1个中括号]Product[第2个中括号]<[第3个中括号]79~"; List<String> string = extractMessageByRegular(msg); System.out.println(string); System.out.println(xiaokuohao(str)); } public static List<String> xiaokuohao(String str) { Pattern p1 = Pattern.compile("\\([^)(]*\\)"); Matcher m = p1.matcher(str); ArrayList<String> list = new ArrayList<String>(); while (m.find()) { list.add(m.group().trim().replace("(", "").replace(")", "")); } return list; } /** * 使用正则表达
获取小括号、中括号内容
最新推荐文章于 2024-07-13 02:39:29 发布
这篇博客主要记录如何使用正则表达式来获取文本中小括号和中括号内的内容,对于日后的编程工作有很好的参考价值。
摘要由CSDN通过智能技术生成