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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:33:46+00:00 2026-05-20T05:33:46+00:00

I was wondering if anyone can help me, I’ve been looking around for regex

  • 0

I was wondering if anyone can help me, I’ve been looking around for regex examples but I still can’t get my head over it.

The strings look like this:

“User JaneDoe, IP: 12.34.56.78”

“User JohnDoe, IP: 34.56.78.90”

How would I go about to make an expression that matches the above strings?

  • 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-20T05:33:47+00:00Added an answer on May 20, 2026 at 5:33 am

    The question is how exactly do you want to match these, and what else do you want to exclude?

    It’s trivial (but rarely useful) to match any incoming string with a simple .*.

    To match these more exactly (and add the possibility of extracting things like the user name and/or IP), you could use something like: "User ([^,]*), IP: (\\d{1,3}(\\.\\d{1,3}){3})". Depending on your input, this might still run into a problem with a name that includes a comma (e.g., “John James, Jr.”). If you have to allow for that, it gets quite a bit uglier in a hurry.

    Edit: Here’s a bit of code to test/demonstrate the regex above. At the moment, this is using the C++0x regex class(es) — to use Boost, you’ll need to change the namespaces a bit (but I believe that should be about all).

    #include <regex>
    #include <iostream>
    
    void show_match(std::string const &s, std::regex const &r) { 
        std::smatch match;
        if (std::regex_search(s, match, r))
            std::cout << "User Name: \"" << match[1] 
                      << "\", IP Address: \"" << match[2] << "\"\n";
        else
            std::cerr << s << "did not match\n";
    }
    
    int main(){ 
    
        std::string inputs[] = {
            std::string("User JaneDoe, IP: 12.34.56.78"),
            std::string("User JohnDoe, IP: 34.56.78.90")
        };
    
        std::regex pattern("User ([^,]*), IP: (\\d{1,3}(\\.\\d{1,3}){3})");
    
        for (int i=0; i<2; i++)
            show_match(inputs[i], pattern);
        return 0;
    }
    

    This prints out the user name and IP address, but in (barely) enough different format to make it clear that it’s matching and printing out individual pieces, not just passing entire strings through.

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

Sidebar

Related Questions

Im in a little over my head, but I was wondering if anyone can
I was wondering if anyone can help me to get this code working...? <?php
wondering if anyone can help. This works, but I was wondering how it would
Wondering if anyone can help - I'm sure this was working before, but I
Wondering if anyone can help me with this annoying but trivial (in terms of
wondering if anyone can help me. I've been searching for a few days for
I'm wondering if anyone can help me. I have a wcf service running over
I was wondering if anyone can help me get started with creating a room
I was wondering if anyone can post an example of how to get a
I was wondering if anyone can help me on this cause its driving me

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.