I am trying to match the correct string using the negative lookahead regular expression.
I want my regex to accept Domain abcd[.]xyz
, but not Bad URL h[xx]ps://abcd[.]xyz
or Evil URL h[xx]p://stu[.]abc
, I have tried many ways to achieve this, but its getting nowhere.
if (str.matches("^(\\w+\\s+)+(?!h\\S+p(s)?://)(.*)$")
{
...
}
The above code actually accepts all strings, which is incorrect. Anyone has a better eagle eye and tell me what I am missing? Thanks.