【发布时间】:2013-12-30 20:22:07
【问题描述】:
我需要一些帮助来挽救我的一天(或我的夜晚)。我想匹配:
- 任意位数
- 用圆括号“()”括起来[括号中只包含数字]
- 如果右括号“)”是字符串中的最后一个字符。
这是我想出的代码:
// this how the text looks, the part I want to match are the digits in the brackets at the end of it
String text = "Some text 45 Some text, text and text (1234)";
String regex = "[no idea how to express this.....]"; // this is where the regex should be
Pattern regPat = Pattern.compile(regex);
Matcher matcher = regPat.matcher(text);
String matchedText = "";
if (matcher.find()) {
matchedText = matcher.group();
}
请帮我解决一下我只能匹配任意数量的数字的魔术表达式,但如果它们被括在括号中并且位于行尾...
谢谢!
【问题讨论】:
标签: java regex brackets digits