版权声明:版权声明:本文为博主原创文章,转载请附上博文链接! https://blog.csdn.net/qq_36051316/article/details/84401267
需要引用:using System.Text.RegularExpressions;
使用语言:C#
环境:.net core 2.1 (当前使用)
核心方法:
Regex rx = new Regex(@"<a.*?</a>", RegexOptions.Compiled | RegexOptions.IgnoreCase);
完整代码:
using System;
using System.Text.RegularExpressions;
namespace netcore.regular.demo
{
class Program
{
static void Main(string[] args)
{
string str1="这个是个a标签:<a class=\"follow-nickName\" href=\"https://me.csdn.net/qq_36051316\" target=\"_blank\">盗理者</a>";
//using System.Text.RegularExpressions;
//建立正则表达式来去掉不要的那些东西。
Regex rx = new Regex(@"<a.*?</a>", RegexOptions.Compiled | RegexOptions.IgnoreCase);
MatchCollection matches = rx.Matches(str1);
//提取我们用正则表达式拿出的东西,再提取我们的字符就ok了
if (matches.Count > 0)
{
var resultStr = matches[0].Value;
System.Console.WriteLine(resultStr);
}
}
}
}