Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何使用正则表达式 Regex获取浏览器url用户输入的部分?
我的网址是这样的:
http://abc.com/weather/2013/9/5
如何从此 url 获取 Date 部分,以及如果用户错误地输入,如何进行异常处理,如下所示:
http://abc.com/weather/2013/9/5/abc
也许像
"[0-9]{4}/[0-9]{1,2}/[0-9]{1,2}" http://abc.com/weather/2013/9/5 = "2013/9/5" http://abc.com/weather/2013/9/5/abc = "2013/9/5" http://abc.com/weather/2013/11/21/abc = "2013/11/21"