日期:2014-05-20  浏览次数:20720 次

用正则表达式提取数字问题
今天1000天可是(267国)

我想用正则表达式提取267该怎么办呀

------解决方案--------------------
Java code

public static void main(String[] args) {
        String str = "今天1000天可是(267国)";
        str = str.replaceAll(".*?\\(.*?(\\d+).*?\\)","$1");
        System.out.println(str);
    }

------解决方案--------------------
for example
Java code
String s = "今天1000天可是(267国)";
Pattern p = Pattern.compile("[(].*?(\\d+).*?[)]");
Matcher m = p.matcher(s);
while (m.find()) {
    System.out.println(m.group(1));
}