【发布时间】:2018-02-13 13:11:16
【问题描述】:
我想从字符串“Max(percentage(%))”或“Max(percentage)”中获取数据,我需要得到的是括号中的“percentage(%)”或“percentage”。我想使用一个正则表达式来实现目标。有人能帮我吗?以下是我的代码:
String str = "Max(percentage)";
Pattern pattern = Pattern.compile("(?<=\\()(.+?)(?=\\))");
String str = "Max(percentage(%))";
Pattern pattern = Pattern.compile("(?<=\\()(.+?)(?<=\\))");
【问题讨论】:
-
实际尝试将其与某个字符串匹配的
Matcher部分在哪里? -
(?i)max\((?<val>.+)\) -
你的正则表达式有效吗?有什么问题?