当前位置: 代码迷 >> ASP >> asp正则表达式解决思路
  详细解决方案

asp正则表达式解决思路

热度:87   发布时间:2012-04-02 19:58:59.0
asp正则表达式
请问各位高手:正则表达式如何把: <img   width=111   src= "ddd "   > 或者 <img   width= "111 "   src= "ddd "   > 中的宽度的值找出来,替换吗?在线等

------解决方案--------------------
格式就是这样吗?如果没有其他变动的话
下面的正则就行
^ <img\s*[^=]*=[ "]?(? <width> [^ "\s]*)[\S\s]*> $
------解决方案--------------------
完整写法

Regex re = new Regex(@ " <img\s*[^=]*=[ " "]?(? <width> [^ " "\s]*)[\S\s]*> ", RegexOptions.None);
MatchCollection mc = re.Matches( " <img width=\ "111\ " src=ddd > ");
foreach (Match ma in mc)
{
Console.WriteLine(ma.Groups[ "width "].Value);
}