微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

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);

原文地址:https://www.jb51.cc/regex/361244.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐