If System.Text.RegularExpressions.Regex.IsMatch("http://blog.csdn.net/precipitant", "http://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?", System.Text.RegularExpressions.RegexOptions.IgnoreCase Or System.Text.RegularExpressions.RegexOptions.Singleline) Then MsgBox("true") Else MsgBox("flase") End If If System.Text.RegularExpressions.Regex.IsMatch("我是塞北的雪", "http://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?", System.Text.RegularExpressions.RegexOptions.IgnoreCase Or System.Text.RegularExpressions.RegexOptions.Singleline) Then MsgBox("true") Else MsgBox("flase") End If
MsgBox("true")
Else
MsgBox("flase")
End If If System.Text.RegularExpressions.Regex.IsMatch("我是塞北的雪", "http://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?", System.Text.RegularExpressions.RegexOptions.IgnoreCase Or System.Text.RegularExpressions.RegexOptions.Singleline) Then
MsgBox("true")
Else
MsgBox("flase")
End If
abcedefffghij,我是要判断fff是不是超链接,结果应该是,但如何做到呢?
string htmltext = "我们的<a href=\"http://www.kaila.cn\">祖国</a>是花园。请访问。我们的<a href=\"http://www.kaila.cn\">祖国</a>是花园。请访问。";
System.Text.RegularExpressions.Regex r = new Regex(@"(<[aA]).*?>.*?(</[aA]>)");
System.Text.RegularExpressions.MatchCollection mc=r.Matches(htmltext);
/*System.Text.RegularExpressions.Match m = r.Match(htmltext);
if(m.Success) {
Response.Write(m.Captures[0].ToString());
}*/
for(int i = 0; i < mc.Count; i++) {
Response.Write(mc[i].Captures[0].ToString()+"<br>");
}
这样可以不?
string strResult;
strResult = Regex.Replace(inputString, @"(?!<a[^<>]*?href\s*=\s*[\'\""\s][^\""\']*[\'\""][^<>]*?>)(好人)(?!<\/a>)", "<a href='http://blog.csdn.net/precipitant'>$1</a>");
MessageBox.Show(inputString + System.Environment.NewLine + strResult );
string strResult;
strResult = Regex.Replace(inputString, @"(?!<a[^<>]*?href\s*=\s*[\'\""\s][^\""\']*[\'\""][^<>]*?>)(好人)(?!<\/a>)", "<a href='http://blog.csdn.net/precipitant'>$1</a>");
MessageBox.Show(inputString + System.Environment.NewLine + strResult );