Thread: C++ 11 regex

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    2
    Rep Power
    0

    Post C++ 11 regex


    Hi,

    I'm new to this forum and also I'm new to regex. I've been following a guide from youtube but the result is not what I expected.

    I'm trying to get the player name (which is Nighty's in my current situation) the 2 digit id (can vary to 3 digit) the steam ID the team color (blue in this case) and the role (scout). Each of these variable may vary later on so the length of each variables is not constant.

    Here is my code:

    PHP Code:
    std::string buffer "\"Nighty's<16><STEAM_X:X:XXXXXXX><Blue>\" changed role to \"scout\"";
            
    std::regex e("\"([[:w:]]+)<([[:w:]]+)><([[:w:]]+)><([[:w:]]+)>\" changed role to \"([[:w:]]+)\"");
            
    std::sregex_iterator regex_buffer(buffer.cbegin(), buffer.cend(), e);
            
    std::sregex_iterator end;
            while (
    regex_buffer != end)
            {
                
    std::cout << regex_buffer->str(0) << std::endl;
                
    std::cout << regex_buffer->str(1) << std::endl;
                
    std::cout << regex_buffer->str(2) << std::endl;
                
    std::cout << regex_buffer->str(3) << std::endl;
                
    std::cout << regex_buffer->str(4) << std::endl;
                
    std::cout << regex_buffer->str(5) << std::endl;
                ++
    regex_buffer;
            } 
    The help would be greatly appreciated, I've been using RegExp web tool to test my match and I could not figure it out.

    Thank you, Nighty's.
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    2
    Rep Power
    0
    This is embarrassing! I've figure it out 5 minutes after posting.
    Here is my solution just in-case someone else need it.

    PHP Code:
    "(.*?)<(.*?)><(.*?)><(.*?)>" changed role to "(.*?)" 

    Comments on this post

    • ManiacDan agrees : Plenty of rep to get you started, thanks for posting the solution.

IMN logo majestic logo threadwatch logo seochat tools logo