Reputation:
It's should match those urls
https://example.com/id/username/
http://example.com/id/username/
https://www.example.com/id/username
http://example.com/id/username/
basically it's should start with http
or https
when maybe www
when example.com
and /id
and last is username which could be anything, and /
is not always in end
username could be anything
I got this so far:
if (input.match(/http\:\/\/example\.com/i)) {
console.log('-');
}
also how to check with regex if urls ends with 7 number like 1234567/
or 3523173
. /
not always in end
Upvotes: 0
Views: 88
Reputation: 189
Use the following regular expression
http(s)?:\/\/(www\.)example.com\/id\/[a-zA-Z0-9]+
You can change [a-zA-Z0-9] as per your username format if you required. See following example:
Upvotes: 1
Reputation: 43169
Without further specification you could use
\bhttps?:.+?example\.com\/[a-zA-Z]+\/\w+\/?(?=\s|\Z)
\b # a word boundary
https?: # http/https:
.+? # anything else afterwards, lazily
example\.com # what it says
\/[a-zA-Z]+\/\w+\/? # /id/username with / optional
(?=\s|\Z) # followed by a whitespace or the end of the string
Upvotes: 0