문제

How can I do the following in C# :

var re = /^\d{4}(\/\d{2}){2} \d{2}(:\d{2}){2}$/;
re.test('2013/03/05 15:22:00'); // returns true
도움이 되었습니까?

해결책 2

The below code should get you where you want to be.

Regex rx = new Regex(@"^\d{4}(\/\d{2}){2} \d{2}(:\d{2}){2}$");
String test = "2013/03/05 15:22:00";

if (rx.IsMatch(test))
{
    //Test String matches
}
else
{
    //Test String does not match
}

다른 팁

You can use the Regex.IsMatch instead (docs).

Regex.IsMatch("2013/03/05 15:22:00", @"^\d{4}(\/\d{2}){2} \d{2}(:\d{2}){2}$"); // true if match
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top