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

  • Home
  • SEARCH
  • 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 9085699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:18:26+00:00 2026-06-16T21:18:26+00:00

i need regex for detect all IPs with ports and without ports but excepting

  • 0

i need regex for detect all IPs with ports and without ports but excepting

93.153.31.151(:27002)

and

10.0.0.1(:27002)

I have got some but I need add exception

\\d{1,3}(?:\\.\\d{1,3}){3}(?::\\d{1,5})?

For java matcher

    String numIPRegex = "\\d{1,3}(?:\\.\\d{1,3}){3}(?::\\d{1,5})?";

    if (pA.matcher(msgText).find()) {
        this.logger.info("Found");

    } else {    
        this.logger.info("Not Found");                  

    }
  • 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-06-16T21:18:27+00:00Added an answer on June 16, 2026 at 9:18 pm

    Without making a statement about better-suited Java classes that can handle IP addreses in a structured manner…

    You can add exceptions to a regular expression using negative look-aheads:

    String numIPRegex = "(?!(?:93\\.153\\.31\\.151|10\\.0\\.0\\.1)(?::27002)?)\\d{1,3}(?:\\.\\d{1,3}){3}(?::\\d{1,5})?";
    

    Explanation:

    (?!                                   # start negative look-ahead
      (?:                                 #   start non-capturing group
        93\.153\.31\.151                  #     exception address #1
        |                                 #     or
        10\.0\.0\.1                       #     exception address #2
      )                                   #   end non-capturing group
      (?:                                 #   start non-capturing group
        :27002                            #     port number
      )?                                  #   end non-capturing group; optional
    )                                     # end negative look-ahead
    \d{1,3}(?:\.\d{1,3}){3}(?::\d{1,5})?  # your original expression
    

    Of course the other obvious alternative would be to test the exceptions up-front one by one and just return false if one exceptions matches. Wrapping them up all up in one single big regex will quickly become very ugly.

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

Sidebar

Related Questions

I've spent some time, but still have to solution. I need regular expression that
All, I need 2 regex expression that will work in .NET to detect whether
I need a regex for date format in python I want March 29 but
I currently have a preg_match to detect http:// and www. etc..... but I want
I need a regex code which will detect format like this 1-2-2-2-1-5.This can be
I need a Regex to detect questions within a text. Example input: please, tell
I need to write regex in this code to detect id on url like
I need to build ONE regular expression that can detect ALL the following strings
I need a regex which will detect multiple occurrences of the new line character
I need help in writing a RegEx able to detect 1 or more instance

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.