一个简单的正则替换 问题 帮帮忙

aierduo 2007-12-29 03:14:47
我的字符串是这样
s="<td valign=\"top\" style=\"font-size: 10.5pt;\"><strong>SMART & BIGGAR";

想将它截取为 SMART & BIGGAR
现在用正则表达式替换<>之间的字符串,如下:
Regex.Replace(s, "<.+>", "");

但是实际它没替换,请问应该怎么写。
谢谢
...全文
59 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
sbqcel 2007-12-29
  • 打赏
  • 举报
回复
调用下面的方法:

/// <summary>
/// html代码替换
/// </summary>
/// <param name="strContent"></param>
/// <returns></returns>
public static string ReplaceHtmlCode(string strContent)
{
string text1 = @"\<[^\<,\>]+\>";
Regex regex1 = new Regex(text1, RegexOptions.Singleline | RegexOptions.Compiled | RegexOptions.IgnoreCase);
MatchCollection collection1 = regex1.Matches(strContent);
for (int num1 = 0; num1 < collection1.Count; num1++)
{
strContent = strContent.Replace(collection1[num1].Value, "");
}
return strContent;
}
aierduo 2007-12-29
  • 打赏
  • 举报
回复
谢谢大家
aierduo 2007-12-29
  • 打赏
  • 举报
回复
sbqcel
具体怎么写我不清楚啊,能帮我写一下吗,谢谢

wangkun9999
如果这样得话我直接用字符串得Replace就行了。
何必这么替换。
现在主要是我不知道<>里得内容是甚么

root_ 2007-12-29
  • 打赏
  • 举报
回复

string s = " <td   valign=\"top\"   style=\"font-size:   10.5pt;\"> <strong> SMART   &   BIGGAR";
string result = Regex.Replace(s, "<[^>]*>", "");
wangkun9999 2007-12-29
  • 打赏
  • 举报
回复

string str="<td valign=\"top\" style=\"font-size: 10.5pt;\"> <strong> SMART & BIGGAR";
string a = System.Text.RegularExpressions.Regex.Replace(str,@"<td valign=""top"" style=""font-size: 10.5pt;""> <strong>(.*?)","$1");
Response.Write(a);


sbqcel 2007-12-29
  • 打赏
  • 举报
回复
替换HTML字符串的正则:
\<[^\<,\>]+\>

1,978

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 其他语言讨论
社区管理员
  • 其他语言社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧