1
var j = /(ftp|http|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?

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

@drogon, why do you think that this is not an answer? Proposing the right tool for the job seems valid to me.
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.