C#에서 실행되는 정규 표현식을 사용하여 문자열에서 모든 일치 항목을 찾는 방법은 무엇입니까?C# Regex가 문자열의 여러 단어와 일치합니다.
아래의 예제 문자열에서 모든 일치 항목을 찾고 싶습니다. 예 :
inputString: Hello (mail) byebye (time) how are you (mail) how are you (time)
나는 예에서 (mail)
및 (time)
을 일치합니다. 괄호는 (
과 )
입니다.
이 문제를 해결하기 위해 다음 코드를 작성했습니다.
string testString = @"(mail)|(time)";
Regex regx = new Regex(Regex.Escape(testString), RegexOptions.IgnoreCase);
List<string> mactches = regx.Matches(inputString).OfType<Match>().Select(m => m.Value).Distinct().ToList();
foreach (string match in mactches)
{
//Do something
}
논리
OR
조건에 사용되는 파이프 (
|
)인가?
완료 !!!! @FishBasketGordo – Nisho