問題:[img]/uploadpic/2007-5/200757132236554.jpg[/img]替換成<img src=/uploadpic/2007-5/200757132236554.jpg>
解決辦法:
using system.text.regularexpressions;
chr = new regex(@"(/[img/])([ /s/t]*?)(/[//img/])",regexoptions.ignorecase);
for (m = chr.match(result); m.success; m = m.nextmatch())
{
result = result.replace(m.groups[0].tostring(),
"<img src=/""+m.groups[2].tostring()+"/" border=0>");
}
c# 提取子匹配字符串的例子
string ll="<td>([//s//s]*?)</td>";
regex r = new regex(ll); //定義組
match m = r.match("<tr class=alt><td>解讀 c# 中的正則表達式</td>");
response.write(m.groups[0].value);
顯示結果為" 解讀 c# 中的正則表達式"
新聞熱點
疑難解答