急急急啊,马上给分,用正则表达式取间内容

yuewh491 2007-01-22 12:12:14
<font>阿斯顿飞金卡手机</font>
请问大家我想对中间的字符串进行截取,
结果成<font>阿斯顿...</font>
请问大家怎么做啊,急四我了
...全文
732 25 打赏 收藏 转发到动态 举报
写回复
用AI写文章
25 条回复
切换为时间正序
请发表友善的回复…
发表回复
-过客- 2007-01-22
  • 打赏
  • 举报
回复
把我搞糊涂了,你所要替换的内容<font color=#00000>阿斯顿飞金卡手机</font>中,除了<font color=#00000>里的内容会变,其它都是固定的吗,还有你替换后的,那个“...”是什么啊,还是就要替换成“阿斯顿飞...”这个字符串
yuewh491 2007-01-22
  • 打赏
  • 举报
回复
要把<font color=#00000>阿斯顿飞金卡手机</font>中的阿斯顿飞金卡手机截掉一部分
变成<font color=#00000>阿斯顿飞...</font>
-过客- 2007-01-22
  • 打赏
  • 举报
回复
汗,要保留哪部分,内容是确定的还是不确定的
如果不确定,有什么规律或是可以给出什么限定条件
yuewh491 2007-01-22
  • 打赏
  • 举报
回复
这样不行啊,我只是想把<font color=#00000>阿斯顿飞金卡手机</font>
中的文字截取一部分,但还是要保留<font color=#00000></font>
用上面的方法就把<font color=#00000></font>去掉了啊
yuewh491 2007-01-22
  • 打赏
  • 举报
回复
谢谢,trying~
-过客- 2007-01-22
  • 打赏
  • 举报
回复
或者这样
string yourStr = ................;
string resultStr = Regex.Replace(yourStr, @"<font[\s\S]*?>([\s\S]*?)</font>","$1" , RegexOptions.IgnoreCase);
richTextBox1.Text = resultStr; //要提取的内容
兔子-顾问 2007-01-22
  • 打赏
  • 举报
回复
mark
liujia_0421 2007-01-22
  • 打赏
  • 举报
回复
sorry..

try..

string str = "<font color=#00000>阿斯顿飞金卡手机</font>";
string s = Regex.Match(str, @"<font[\s\S]*>([\s\S]+)</font>").Groups[1].Value;
Console.WriteLine(s);


输出:
阿斯顿飞金卡手机
-过客- 2007-01-22
  • 打赏
  • 举报
回复
string yourStr = ................;
Match m = Regex.Match(yourStr, @"(?<=<font[\s\S]*?>)([\s\S]*?)(?=</font>)", RegexOptions.IgnoreCase);
richTextBox1.Text = m.Groups[1].Value; //要提取的内容
liujia_0421 2007-01-22
  • 打赏
  • 举报
回复
don't forget

using System.Text.RegularExpressions;
liujia_0421 2007-01-22
  • 打赏
  • 举报
回复
try..

string str = "<font>阿斯顿飞金卡手机</font>";
string s = Regex.Match(str, @"<font>([\s\S]+)</font>").Groups[1].Value;
Console.WriteLine(s);
yuewh491 2007-01-22
  • 打赏
  • 举报
回复
怎么用啊
System.Text.RegularExpressions.Regex.Replace(str,"(?<=<font[\s\S]*?>)([\s\S]*?)(?=</font>)","");
是这样嘛,报错啊
-过客- 2007-01-22
  • 打赏
  • 举报
回复
试下
(?<=<font[\s\S]*?>)([\s\S]*?)(?=</font>)
yuewh491 2007-01-22
  • 打赏
  • 举报
回复
大家来啊
yuewh491 2007-01-22
  • 打赏
  • 举报
回复
font里可能有颜色
<font color=#00000>阿斯顿飞金卡手机</font>
怎么做啊,谢谢喇
xk2y 2007-01-22
  • 打赏
  • 举报
回复
........
xiao7cn 2007-01-22
  • 打赏
  • 举报
回复
< font >这样的能匹配么
兔子-顾问 2007-01-22
  • 打赏
  • 举报
回复
……
沾光了,我好像没回答问题。路过也有分。
-过客- 2007-01-22
  • 打赏
  • 举报
回复
其实只要需求明确了,只要正则能做到的,写出正则还是很容易的
yuewh491 2007-01-22
  • 打赏
  • 举报
回复
谢谢喇,就是这样,正则表达式好复杂啊
结贴
加载更多回复(5)

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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