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 4562988
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T18:17:39+00:00 2026-05-21T18:17:39+00:00

I am trying to take a string in C++ and find all IP addresses

  • 0

I am trying to take a string in C++ and find all IP addresses contained inside, and put them into a new vector string.

I’ve read a lot of documentation on regex, but I just can’t seem to understand how to do this simple function.

I believe I can use this Perl expression to find any IP address:

re("\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b");

But I am still stumped on how to do the rest.

  • 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-21T18:17:40+00:00Added an answer on May 21, 2026 at 6:17 pm

    Perhaps you’re looking for something like this. It uses regex_iterator to get all matches of the current pattern. See reference.

    #include <boost/regex.hpp>
    #include <iostream>
    #include <string>
    
    int main()
    {
        std::string text(" 192.168.0.1 abc 10.0.0.255 10.5.1 1.2.3.4a 5.4.3.2 ");
        const char* pattern =
            "\\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)"
            "\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)"
            "\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)"
            "\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b";
        boost::regex ip_regex(pattern);
    
        boost::sregex_iterator it(text.begin(), text.end(), ip_regex);
        boost::sregex_iterator end;
        for (; it != end; ++it) {
            std::cout << it->str() << "\n";
            // v.push_back(it->str()); or something similar     
        }
    }
    

    Output:

    192.168.0.1
    10.0.0.255
    5.4.3.2
    

    Side note: you probably meant \\b instead of \b; I doubt you watnted to match backspace character.

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

Sidebar

Related Questions

I'm trying to find the amount of space/width that a string would take when
Im trying to find a solution to search for a text string Tony contained
I need to take find all unique values from the below and pass them
I'm trying to take this string where lowercase(pdd.last_name) like 'albert%' and replace pdd with
I'm trying to take a text string, (e.g. the word testing) and calculating if
I'm trying to take a numeric value in a string and raise it by
I'm trying to take the basic youtube embed code and bbreak it up into
I'm trying to take a string of text, and extract the rest of the
I am trying to find a way in Ruby to take a UTF-8 byte
I'm trying to find an elegant way of encapsulating XML into a C# class.

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.