c# 正则获取html标签内容,c# – 使用正则表达式在多个HTML标记之间获取文本
生活随笔
收集整理的這篇文章主要介紹了
c# 正则获取html标签内容,c# – 使用正则表达式在多个HTML标记之间获取文本
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
使用正則表達式,我希望能夠在多個DIV標記之間獲取文本.例如,以下內容:
first html taganother tag輸出:
first html tag
another tag
我使用的正則表達式模式只匹配我的最后一個div標簽并錯過了第一個.
碼:
static void Main(string[] args)
{
string input = "
This is a testThis is ANOTHER test";string pattern = "(
)(.*)()";MatchCollection matches = Regex.Matches(input, pattern);
Console.WriteLine("Matches found: {0}", matches.Count);
if (matches.Count > 0)
foreach (Match m in matches)
Console.WriteLine("Inner DIV: {0}", m.Groups[2]);
Console.ReadLine();
}
輸出:
匹配發現:1
內部DIV:這是另一個測試
總結
以上是生活随笔為你收集整理的c# 正则获取html标签内容,c# – 使用正则表达式在多个HTML标记之间获取文本的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 宜春治疗男性精子活力低最好的医院推荐
- 下一篇: c# 口口乱码_c# 乱码解决方法