正则表达式 匹配某一网页内容里的一组字符串中的数字 比如 珠宝/钻石/翡翠/黄金(17048) 怎么把这个数字拿出来 
不能直接匹配数字,因为这个网页内容里还有好多数字

解决方案 »

  1.   


    public static void main(String[] a){
    String regex="[0-9]*";
            String str="珠宝/钻石/翡翠/黄金(17048) ";
            String[] result=getStrExpression(regex,str);
            for(String s:result){
                System.out.println(s);
            }}public static int[] b = new int[9];
       public static String[] getStrExpression(String regex,String str){ 
            
            List<String> temp = new ArrayList<String>();
            Pattern p = Pattern.compile(regex);
            Matcher m = p.matcher(str);
            while(m.find()){
                temp.add(m.group());
            }
            String[] result=new String[temp.size()];
            temp.toArray(result);
            return result;
        } 
     
      

  2.   


    String regex = "([\\u4e00-\\u9fa5]+/?)+\\((\\d+)\\)";
    String str = "珠宝/钻石/翡翠/黄金(17048)";
    Matcher m = Pattern.compile(regex).matcher(str);
    while (m.find())
    System.out.println(m.group(2));
      

  3.   

    String aa = "珠宝/钻石/翡翠/黄金(17048)";
    Pattern p = Pattern.compile("([^\\(])(\\d+)");
    Matcher m = p.matcher(aa);
    while (m.find()) {
    System.out.println(m.group());
    }