Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6068531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:43:30+00:00 2026-05-23T09:43:30+00:00

this is my first question so please be nice :). I’m trying to build

  • 0

this is my first question so please be nice :). I’m trying to build a regexp to get an array of IPs that are both valid (OK, at least with the proper IPv4 format) and NOT a private IP according to RFC 1918. So far, I’ve figured out a way to get exactly the opposite, I mean succcssfuly matching private IPs, so all what I need is a way to revert the assertion. This is the code so far:

// This is an example string
$ips = '10.0.1.23, 192.168.1.2, 172.24.2.189, 200.52.85.20, 200.44.85.20';

preg_match_all('/(?:10\.\d{1,3}|172\.(?:1[6-9]|2\d|3[01])|192\.168)\.\d{1,3}\.\d{1,3}/', $ips, $matches);

print_r($matches);

// Prints:
Array
(
  [0] => Array
  (
    [0] => 10.0.1.23
    [1] => 192.168.1.2
    [2] => 172.24.2.189
  )
)

And what I want as result is:

Array
(
  [0] => Array
  (
    [0] => 200.52.85.20
    [1] => 200.44.85.20
  )
)

I’ve tried changing the first part of the expression (the lookahead) to be negative (?!) but this messes up the results and don’t even switch the result.

If you need any more informartion please feel free to ask, many thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T09:43:31+00:00Added an answer on May 23, 2026 at 9:43 am

    If all you want to do is to exclude a relatively small range of ip’s, you could do this
    (if I didn’t make any typo’s):

    /(?!\b(?:10\.\d{1,3}|172\.(?:1[6-9]|2\d|3[01])|192\.168)\.\d{1,3}\.\d{1,3}\b)\b(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b)/
    

    Example in Perl:

    use strict;
    use warnings;
    
    my @found = '10.0.1.23, 192.168.1.2, 172.24.2.189, 200.52.85.20, 200.44.85.20' =~
    /
    (?!
       \b
       (?:
            10\.\d{1,3}
          |
            172\.
            (?:
                1[6-9]
              | 2\d
              | 3[01]
            )
          |
            192\.168
       )
       \.\d{1,3}
       \.\d{1,3}
       \b
    )
    \b(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b)
    /xg;
    
    for (@found) {
        print "$_\n";
    }
    

    Output:

    200.52.85.20
    200.44.85.20

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my first question so please be patient :) Background: I'm implementing an
So this question will get technical – eventually – but first check out Hanselminutes
First question on here so please be nice :) I know very little about
first question to StackOverflow, please be gentle. I am trying to find the equation
This is my first question on SO, so if it seems beyond dumb, please
First question on SOF, please be gentle if this may be a stupid question.
This is my first question on SO, so please be gentle :) I've recently
This is my first question here so please bear with me - I apologise
This is my first question asked here at stackoverflow, so bear with me please
Note 1: This is my first question here. Please be gentle. Note 2: Yes,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.