user34537
user34537

Reputation:

NOT match the regex

Due to limitations i need to write ONE regex and i would like to blacklist instead of whitelist certain strings (or sites)

Here i want to disallow youtube and IP address. Below is code that matches the two site. How can i NOT match them and allow the two google (or any other site) to match?

Here is some C# code i used to test my regex.

        var mq = Regex.Match("http://google.com\nhttp://youtube.com\nhttp://google.com/ddhf\n72.72.72.72\n",
            @"(.*youtube\.com.*|\d+\.\d+\.\d+\.\d+)", RegexOptions.Multiline);
        while (mq.Success)
        {
            string sz = mq.Groups[0].Value;
            Console.WriteLine(sz);
            mq = mq.NextMatch();
        }

        return;

Upvotes: 0

Views: 2032

Answers (1)

Konamiman
Konamiman

Reputation: 50323

You need the ?! construct. So it would be:

(?!.*youtube\.com.*|\d+\.\d+\.\d+\.\d+)

Upvotes: 2

Related Questions