代码:
<a id="J_BuyerRate" href="javascript:void(0)">
                                18
                            </a>
要用正则表达式 提取 中间的数字 18不知道怎么写注意空白处(18前后都有一部分空白)

解决方案 »

  1.   


    Pattern p = Pattern.compile("<a .*>\\s*([\\d]+)\\s*</a>");

    Matcher m = p.matcher("<a id=\"J_BuyerRate\" href=\"javascript:void(0)\"> 18 </a>");

    m.find();
    String a = m.group(1);
    System.out.println(a);试一试。
      

  2.   


    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
      

  3.   

    实际上我需要这个url= pp
    wstr=getHTTPPage(url) 
    Set objRegExp=New RegExp 
    objRegExp.IgnoreCase=true
    objRegExp.Global=FALSE
    objRegExp.Pattern="<a id=""J_BuyerRate"" href=""javascript:void(0)"">(.*?)</a>"
    set Matches=objRegExp.Execute(wstr)
    ooyu=Matches(0).SubMatches(0)
    输出ooyuobjRegExp.Pattern="" 引号中是<a id="J_BuyerRate" href="javascript:void(0)">
      18
      </a>
    需要一个正则
      

  4.   

    Pattern p = Pattern.compile("<a .*>\\s*([\\d]+)\\s*</a>");你没有注意到这个吧?
      

  5.   

    vbscript?
    objRegExp.Pattern="/<a[^>]*?>\s*(.*?)\s*<\/a>/"
      

  6.   

    恩如果具体到我这个,应该怎么写正则才能获得 18这个数值呢
    url= pp
    wstr=getHTTPPage(url)  
    Set objRegExp=New RegExp  
    objRegExp.IgnoreCase=true
    objRegExp.Global=FALSE
    objRegExp.Pattern=""    
                        引号中的代码:
    <a id="J_BuyerRate" href="javascript:void(0)">
                     18
                     </a>set Matches=objRegExp.Execute(wstr)
    ooyu=Matches(0).SubMatches(0)
    输出ooyu输出ooyu
    ooyu=18  或者18位置上的数值
    这里面href="javascript:void(0)">后面有个换行
    18前面有一大段空白
    有点郁闷
      

  7.   

    vbscript里多行模式这么指定?
    objRegExp.Pattern="/<a[^>]*?>\s*(.*?)\s*<\/a>/m"你试下啊。我在javascript里面用上面的正则是可以取到18的。
    vb的写法不太熟悉。
      

  8.   

    Try:/<a[^>]*>[\s\S]*?(\d+)[\s\S]*?<?a>/
      

  9.   

    <[^>]*>,这个是取得<>的,你可以replaceAll("<[^>]*>",""),剩下的就是你需要的了!
      

  10.   

    /<a[^>]*>[\s\S]*?(\d+)[\s\S]*?<?a>/这个不行源码中还有其他代码
    必须有<a id="J_BuyerRate" href="javascript:void(0)">后面跟正则获取数值
    <a id="J_BuyerRate" href="javascript:void(0)">后面有一个换行,还有一大段空格
      

  11.   

    这样呢?objRegExp.Pattern="[^<a]*?<a[^>]*?>\s*(.*?)\s*<\/a>[^<\/a>]*";
      

  12.   

    [^<a]*?<a[^>]*?>\s*(.*?)\s*<\/a>[^<\/a>]*匹配的<a href=.....................</a>要是<a id="J_BuyerRate" href="javascript:void(0)">
                     18                 </a>有换行和空白怎么写呢