using System;
using System.Text.RegularExpressions;
public class Test
{
public static void Main()
{
string[] strings = { "/api/ping.json",
"/api/ping",
"/api/ping/xxx/sss.json",
"/api/ping.xml",
"/api/ping/.json",
"/api/pingpong",
"/api/ping_pong",
"/api/ping-pong"
};
string pattern = @"/api/ping(?:(?:/[^/\s]+)*\.\S+|$)";
foreach (String s in strings) {
if (Regex.IsMatch(s, pattern)) {
Console.WriteLine("Valid: {0}", s);
} else {
Console.WriteLine("Invalid: {0}", s);
}
}
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uVGV4dC5SZWd1bGFyRXhwcmVzc2lvbnM7CgpwdWJsaWMgY2xhc3MgVGVzdAp7CglwdWJsaWMgc3RhdGljIHZvaWQgTWFpbigpCgl7CgkJc3RyaW5nW10gc3RyaW5ncyA9IHsgIi9hcGkvcGluZy5qc29uIiwKICAgICAgICAgICAgICAgICIvYXBpL3BpbmciLAogICAgICAgICAgICAgICAgIi9hcGkvcGluZy94eHgvc3NzLmpzb24iLAogICAgICAgICAgICAgICAgIi9hcGkvcGluZy54bWwiLAogICAgICAgICAgICAgICAgIi9hcGkvcGluZy8uanNvbiIsCiAgICAgICAgICAgICAgICAiL2FwaS9waW5ncG9uZyIsCiAgICAgICAgICAgICAgICAiL2FwaS9waW5nX3BvbmciLAogICAgICAgICAgICAgICAgIi9hcGkvcGluZy1wb25nIgogICAgICAgICAgICAgICAgfTsKICAgICAgICAgICAgc3RyaW5nIHBhdHRlcm4gPSBAIi9hcGkvcGluZyg/Oig/Oi9bXi9cc10rKSpcLlxTK3wkKSI7CiAgICAgICAgICAgIGZvcmVhY2ggKFN0cmluZyBzIGluIHN0cmluZ3MpIHsKICAgICAgICAgICAgICAgIGlmIChSZWdleC5Jc01hdGNoKHMsIHBhdHRlcm4pKSB7CiAgICAgICAgICAgICAgICAgICAgQ29uc29sZS5Xcml0ZUxpbmUoIlZhbGlkOiB7MH0iLCBzKTsKICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgQ29uc29sZS5Xcml0ZUxpbmUoIkludmFsaWQ6IHswfSIsIHMpOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9Cgl9Cn0=