문자열에서 값을 캡처하는 데 문제가 있습니다. 나는 단지 T
또는 :
을 붙잡고 싶지 않은 번호 만 원합니다. 이 실패 테스트는 다음과 같이 설명합니다 :정규 표현식 캡쳐
[TestMethod]
public void RegExTest()
{
var rex = new Regex("^T([0-9]+):"); //as far as I understand, the() denote the capture group
var match = rex.Match("T12:abc");
Assert.IsTrue(match.Success);
Assert.IsTrue(match.Groups[0].Success);
Assert.AreEqual("12", match.Groups[0].Captures[0]); //fails, actual is "T12:"
}
같이해야한다. 당신의 정규 표현식은'^ (?: T) ([0-9] +) (? : \ :) $' –
@AndreCalil이되어야합니다. 그래도 작동하려면'Groups [1] 결과. 감사. – weston
첫 번째 그룹은 그룹 [1]입니다. 그룹 [0]은 전체 일치입니다. – Toto