代码:
<a id="J_BuyerRate" href="javascript:void(0)">
18
</a>
要用正则表达式 提取 中间的数字 18不知道怎么写注意空白处(18前后都有一部分空白)
<a id="J_BuyerRate" href="javascript:void(0)">
18
</a>
要用正则表达式 提取 中间的数字 18不知道怎么写注意空白处(18前后都有一部分空白)
调试欢乐多
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);试一试。
import java.util.regex.Matcher;
import java.util.regex.Pattern;
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>
需要一个正则
objRegExp.Pattern="/<a[^>]*?>\s*(.*?)\s*<\/a>/"
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前面有一大段空白
有点郁闷
objRegExp.Pattern="/<a[^>]*?>\s*(.*?)\s*<\/a>/m"你试下啊。我在javascript里面用上面的正则是可以取到18的。
vb的写法不太熟悉。
必须有<a id="J_BuyerRate" href="javascript:void(0)">后面跟正则获取数值
<a id="J_BuyerRate" href="javascript:void(0)">后面有一个换行,还有一大段空格
18 </a>有换行和空白怎么写呢