Reputation: 3183
Suppose there are the following strings:
https://domain1.com
https://domain2.com
https://domain3.com
https://testdomain.com
https://domain4.com
https://domain5.com
random text
293928382
How can I match only strings that have http
but also exclude ones that contain testdomain
for example? Currently I have this which excludes testdomain
^((?!testdomain).)*$
However I don't know how to combine the http
matching part with the above expression. Can someone please help me combine the above with matching http
as well?
The objective is to match:
https://domain1.com
https://domain2.com
https://domain3.com
https://domain4.com
https://domain5.com
Thanks!
Upvotes: 1
Views: 27
Reputation: 784958
You may use this regex with a negative lookaheadd:
^https?://(?!(?:www\.)?testdomain\.).+$
RegEx Details:
^https?://
: Match http://
or https://
at the start(?!(?:www\.)?testdomain\.)
: Negative lookahead to assert that we don't have www.testdomain.com
or testdomain.com
right after.+$
: Match 1+ of any characterUpvotes: 1