2022. 7. 21. 16:17

C# 특정문자열로 둘러쌓인 문자열 추출

만일 문자열 중 %%...%%로 되어 있는 부분의 내용만 따로 꺼내고 싶으면 아래와 같이 하면 됨

적용 정규식 : %%([^%%]+)%%

이렇게 하고 c#의 Match.groups[1].value로 가져옴

string strFileSrc = "이것은 %%시험_111%% 문자열입니다";
MatchCollection mc = Regex.Matches(strFileSrc, "%%([^%%]+)%%");
List<string> lstrKeywordList = new List<string>();

foreach (Match match in mc)
{
	lstrKeywordList.Add(match.Groups[1].Value);
    //Console.WriteLine("단어 : {0}", match.Groups[1]);
}