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

简介: 1、正则替换字符-------------------------------------------------------------------------------------------------------------------...
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);
目录
相关文章
|
7月前
常用正则表达式
常用正则表达式
|
17天前
|
Java
正则表达式
正则表达式
|
2月前
|
JavaScript 前端开发 Java
正则表达式详细讲解
正则表达式详细讲解
正则表达式详细讲解
|
12月前
|
JavaScript 数据安全/隐私保护
|
移动开发 JavaScript 前端开发
正则表达式总结
什么是正则表达式? 正则表达式(Regular Expression)是用于匹配字符串中字符组合的模式。在JavaScript中,正则表达式也是对象。
77 1
|
数据采集 机器学习/深度学习 移动开发
我学会了,正则表达式
爬虫是**非常的**的强大,相信不少朋友都有所耳闻,它帮助我们更快地“获得”我们所要关键数据。那么,它怎么知道我们要需要什么内容?它又是如何工作的?在这篇文章里,我们一起来看看。
76 0
我学会了,正则表达式
|
C#
正则表达式01
正则表达式01
147 0
正则表达式01
|
Windows
正则表达式汇总
常用正则表达式
162 0