java正则最后⼀个字符_Java正则表达式:如果结束括号是字符串中的最后⼀个字符,则匹配。。。
我需要⼀些帮助来保存我的⼀天(或我的夜晚).我想匹配:
>任意数量的数字
>⽤圆括号括起来“()”[括号中除了数字之外别⽆其他]
>如果结束括号“)”是字符串中的最后⼀个字符.
这是我提出的代码:
// 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 ]"; // this is where the regex should be
Pattern regPat = Patternpile(regex);
Matcher matcher = regPat.matcher(text);
String matchedText = "";
if (matcher.find()) {正则表达式获取括号内容
matchedText = up();
}
请帮我解决我只能设置匹配任意数字的神奇表达式,但如果它们括在括号中并且位于⾏尾,请不要帮助我…
谢谢!