본문으로 바로가기

Regex 활용하여 파싱하기

category Coding/C# 2015. 11. 12. 22:08
반응형

using System.Text.RegularExpressions;

string data = Winhttp.ResponseText; // 원본

string regex = "<title>(.*)</title>"; // 패턴

Match match = Regex.Match(data, regex);

if (match.Success)

{

result = match.Groups[1].Value;

}


이런식으로 하나만 뽑을수도 있고


using System.Text.RegularExpressions;

List<string> hide = new List<string>();

string data = Winhttp.ResponseText;

Regex regex = new Regex("<span class=\"name\">(.*)</span>");

MatchCollection mc = regex.Matches(data);

foreach (Match m in mc)

{

    for (int i = 1; i < m.Groups.Count; i++)

    {

        hide.Add(m.Groups[i].Value);


    }

}


이런식으로 전부다 뽑을수도 있다

리스트 사용해서 원하는것만 쓰던가..뭐 여러가지 방법이 있을듯

반응형