28,391
社区成员
发帖
与我相关
我的任务
分享
protected string GetImgUrl(string img) {
Regex regex = new Regex(@"<img.*src=[\""|\']?([^\""]*)[\'|\""]?[^/]*[/]?>", RegexOptions.Compiled | RegexOptions.IgnoreCase );
string str = "";
foreach (Match matchItem in regex.Matches(img))
{
if (matchItem.Groups[1] != null)
{
str += matchItem.Groups[1].Value;
}
}
return str;
}
Function getImg(content)
Dim regEx, Match,i
Set regEx = New RegExp
regEx.Pattern = "[^/]\w*\.\w*" '这个地方,自己找一下该怎么改,ASP的写法我有点忘了
regEx.IgnoreCase = true
regEx.Global = True
Matches = regEx.test(content)
for i=0 to UBound(Matches)-1
getImg=getImg+Matches(i)
if i<UBound(Matches)-1 then getImg=getImg+"|"
next
End Function
ASP调用正则的通用函数
Function CheckExp(patrn, strng)
Dim regEx, Match ' 建立变量。
Set regEx = New RegExp ' 建立正则表达式。
regEx.Pattern = patrn ' 设置模式。
regEx.IgnoreCase = true ' 设置是否区分字符大小写。
regEx.Global = True ' 设置全局可用性。
Matches = regEx.test(strng) ' 执行搜索。
CheckExp = matches
End Function
<script type="text/javascript">
var content='<img src="upload/img/1234455.gif">,<img src="upload/img/f22455.png">,<img src="upload/img/1733455.png">';
function getImg(content){
return content.match(/[^/]\w*\.\w*/ig).join("|");
}
alert(getImg(content));
</script>
<script type="text/javascript">
var content='<img src="upload/img/1234455.gif">,<img src="upload/img/f22455.png">,<img src="upload/img/1733455.png">';
function getImg(content){
var ns=content
ns=ns.replace(/<img src="upload\/img\//g,'').replace(/">,/g,'|').replace(/">/g,'');
return ns;
}
alert(getImg(content));
</script>
<script type="text/javascript">
var content='<img src="upload/img/1234455.gif">,<img src="upload/img/f22455.png">,<img src="upload/img/1733455.png">';
function getImg(content){
var ns=content //,r=/*img\/(*.*)">/g
ns=ns.replace(/<img src="upload\/img\//g,'');
ns=ns.replace(/">,/g,'|');
ns=ns.replace(/">/g,'');
return ns;
}
alert(getImg(content));
</script>