1

C#で次のことを行うにはどうすればよいですか:

var re = /^\d{4}(\/\d{2}){2} \d{2}(:\d{2}){2}$/;
re.test('2013/03/05 15:22:00'); // returns true
4

2 に答える 2

6

Regex.IsMatch代わりに ( docs )を使用できます。

Regex.IsMatch("2013/03/05 15:22:00", @"^\d{4}(\/\d{2}){2} \d{2}(:\d{2}){2}$"); // true if match
于 2013-03-05T14:27:10.737 に答える
4

以下のコードで、目的の場所に移動できます。

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
}
于 2013-03-05T14:30:50.843 に答える