1

I am making an expression for validation the url in a right format. Expression works but i want if the url go beyond .com then it should not match. I mean expression starts from HTTPS/HTTP ---> .com. It should not go beyond .com like https://www.google.com/abcdefgh...

Regex:

 "/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i"

1 Answer 1

1

After some minor changes and adding the lookahead (?=.*?\.com$), your working regex would look like this:

\b(?:(?:https?|ftp):\/\/)?www\.(?=.*?\.com$)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]

(?=.*?\.com$) validates that the regex will match the url only if it has .com in the end

Click for Demo

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

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.