How to match all URLs except one using regex?

To match all URLs except one using regex, you can use a negative lookahead assertion in your regular expression. The negative lookahead assertion specifies a condition that must not be met for a match to occur. Here’s a general example:

Suppose you want to match all URLs except for “” You can construct a regex pattern like this:


  • ^: Start of the string.
  • (?!.*example\.com): Negative lookahead assertion that checks if “” is not present anywhere in the string.
  • .*: Match any characters zero or more times.
  • .*$: Match until the end of the string.

Here’s how you can use this regex pattern in JavaScript:

In this example, the regex pattern matches all URLs that do not contain “” You can adapt the regex and replace “” with the specific URL you want to exclude.