Reputation: 83
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"
Upvotes: 1
Views: 106
Reputation: 10360
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
Upvotes: 1