【发布时间】:2013-08-12 06:25:41
【问题描述】:
假设我要转换这些字符串:
www.myexample.com 和http://www.myexample.com
进入:
<a href='http://www.myexample.com'>http://www.myexample.com</a>
使用 Regex.Replace
我想出了这个:
Regex.Replace(string, pattern, "<a href=\"$&\">$&</a>")
我的问题是我不知道如何检查匹配的字符串 $& 是否以 http:// 开头并在必要时添加它。
有什么想法吗?
【问题讨论】:
-
你一直使用的模式是什么?