Solution:
The ^(?!stack.com$).*
regex matches any string (even an empty one) that does not start with stack.com
.
To match stack.com
but not inside stack.com/wp-admin
, you need a negative lookahead:
/stack\.com(?!\/wp-admin)/
^^^^^^^^^^^^^
Or better, with word boundaries to only match whole words:
/\bstack\.com\b(?!\/wp-admin)/
See the regex demo
Details:
\b
– a leading word boundarystack\.com
– a literal stringstack.com
(a dot must be escaped)\b
– a trailing word boundary(?!\/wp-admin)
– a negative lookahead that fails the match if there is/wp-admin
immediately to the right of the current location.