我需要从这个文本中单独提取数字我使用子字符串来提取细节,有时数字会减少,所以我得到一个错误值...
example(16656);
最佳答案
使用Pattern
编译你的正则表达式和Matcher
获得特定的捕获组。我使用的正则表达式是:
example\((\d+)\)
捕获括号内的数字 (\d+
)。所以:
Pattern p = Pattern.compile("example\\((\\d+)\\)");
Matcher m = p.matcher(text);
if (m.find()) {
int i = Integer.valueOf(m.group(1));
...
}
关于java - 我如何使用正则表达式 java 提取值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3593802/