我需要一些帮助来保存我的一天(或我的夜晚)。我想搭配:
这是我想出的代码:
// 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();
}
请帮助我解决神奇的表达式,我只能设法匹配任意数量的数字,但是如果它们放在方括号中并且在行的末尾,则不能匹配...
谢谢!
您可以尝试以下正则表达式:
String regex = "\\(\\d+\\)$";
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句