private static void Main(string[] arg)
{
var text = "";
//文本读取器
using (TextReader reader = new StreamReader(@"D:\Users\admin\Desktop\cstext.txt", System.Text.Encoding.UTF8))
{
//一次性读完
string textContent = reader.ReadToEnd();
//输出读取的内容
//Console.WriteLine(textContent);
text = textContent;
}
string par = "";
Regex reg = new Regex(@"(?<gr1><div\spage-id=.[0-9]{4})(?<gr2>.\sdata-cms=.[a-z]{7}.)");
var a = reg.Matches(text);
var b = a[0].Groups["gr1"].Value;
//Console.WriteLine(a.Value);
}
1.匹配任意字符 .
2.匹配4个0-9的数字[0-9]{4}
3.匹配4个a-z字母 [a-z]{4}
4.(?<gr1>)给正则表达式分组方便使用group["组名"]来提取中间的数据
详见msdn官方文档 https://learn.microsoft.com/zh-cn/dotnet/standard/base-types/character-classes-in-regular-expressions
标签:Regex,string,记录,C#,text,textContent,正则表达式,var From: https://www.cnblogs.com/supercoding/p/17191975.html