加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Regex 正则替换指定范围全部字符串

发布时间:2020-12-14 01:34:20 所属栏目:百科 来源:网络整理
导读:1、正则替换字符-------------------------------------------------------------------------------------------------------------------------- private static Regex HrefAttribute = new Regex("href=".*?"",RegexOptions.IgnoreCase); html = HrefAt
1、正则替换字符-------------------------------------------------------------------------------------------------------------------------- private static Regex HrefAttribute = new Regex("href=".*?"",RegexOptions.IgnoreCase); html = HrefAttribute.Replace(html,string.Empty
2、正则替换字符--------------------------------------------------------------------------------------------------------------------------- string strxmlstr = tw.ToString(); Regex HrefAttribute = new Regex("<jiesuancontract>([^<]*)</jiesuancontract>|<yusuanprice>([^<]*)</yusuanprice>|<chushengprice>([^<]*)</chushengprice>|<shengdingprice>([^<]*)</shengdingprice>",RegexOptions.IgnoreCase); string html = HrefAttribute.Replace(strxmlstr,string.Empty).Trim(); 3、正则提取字符---------------------------------------------------------------------------------------------------------------------------- <html> <head> <meta http-equiv="content-type" content="text/html; charset=gb2312"> <title>哈哈哈哈</title> </head> <body style="margin:0px"><center>你好世界!</center>"><center>你好世界!</center></body></html> 设textBox1.text="为你的文本"; string regexStr = @"<center>([^<]*)</center>"; Match mc = Regex.Match(textBox1.Text.Replace("n",""),regexStr,RegexOptions.IgnoreCase); MessageBox.Show("结果为:" + mc.Groups[1].Value);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读