10
단순화 된 예제에는 대소 문자가 구분 된 두 개의 정규식과 다른 대소 문자가 구분되어 있습니다. 아이디어는 에 결과를 결합하는 IEnumerable 컬렉션 (아래의 "combined"참조)을 만드는 것입니다..Net Regex에서 MatchCollections를 효율적으로 결합
string test = "abcABC";
string regex = "(?<grpa>a)|(?<grpb>b)|(?<grpc>c)]";
Regex regNoCase = new Regex(regex, RegexOptions.IgnoreCase);
Regex regCase = new Regex(regex);
MatchCollection matchNoCase = regNoCase.Matches(test);
MatchCollection matchCase = regCase.Matches(test);
//Combine matchNoCase and matchCase into an IEnumerable
IEnumerable<Match> combined= null;
foreach (Match match in combined)
{
//Use the Index and (successful) Groups properties
//of the match in another operation
}
이 실제로, MatchCollections 결과의 수천을 포함 할 수 있습니다 긴 동적으로 생성 된 정규 표현식에를 사용하여 자주 실행되는, 그래서 난 여전히 LINQ를 배우고 등을 배열로 결과를 복사에서 멀리 주저하고 싶습니다과 이들을 결합하는 방법에 대한 퍼지 또는 성능 저하가 이미 부진한 프로세스에 어떤 영향을 미칠지에 대해서.
Match.Success
속성이 true
코드인지하여 시퀀스의
IEnumerable<Match>
에의'MatchCollection
변환 :
의도적으로 결과가 겹치기를 원하지 않는 한 .Concat()이 .Union()보다 좋을 수도 있습니다. – jmnben