开发者

ASP.NET MVC regular expression url

var j = /(ftp|h开发者_运维知识库ttp|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?\//;

I want to restrict only one / coming at the end of the string. How can I restrict that in the above regular expression?


Please don't tell me you are using regular expressions to validate urls when there's the Uri.TryCreate method.


After the port-part you should have something like:

((match_part)+?(\/(match_part)+?)?)?

This will allow at least one char in each part, and zero or one part first, if one, then zero or one part more. You have to replace match_part with what you actually want to match, I didnt copy your expression since, for example, the hash (#) isn't valid in the url, just at the end

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜