Raised This Month: $ Target: $400
 0% 

c++ 11 regex


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Mathias.
Veteran Member
Join Date: Aug 2010
Location: Canada is my city
Old 09-29-2013 , 13:41   c++ 11 regex
Reply With Quote #1

I got some problem with regex and I can't really figure out the issue I have. By the way I'm pretty new with regex and I've followed a guide to get through it.

Here 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;
        } 
Mathias. is offline
Chrisber
AlliedModders Donor
Join Date: Jul 2007
Location: localhost
Old 09-29-2013 , 16:47   Re: c++ 11 regex
Reply With Quote #2

Use an online regex tester tool. When the pattern does not match this has nothing to do with any C++ specific. It's a general problem in your pattern.
Chrisber is offline
Mathias.
Veteran Member
Join Date: Aug 2010
Location: Canada is my city
Old 09-30-2013 , 01:03   Re: c++ 11 regex
Reply With Quote #3

Thx for the advise, I've been playing around with the regexp web tool for hours and I could not figure it out.
Mathias. is offline
Mathias.
Veteran Member
Join Date: Aug 2010
Location: Canada is my city
Old 09-30-2013 , 01:36   Re: c++ 11 regex
Reply With Quote #4

Alrite I got it, not the best but work the way I want:

PHP Code:
"(.*?)<(.*?)><(.*?)><(.*?)>" changed role to "(.*?)" 
(.*?) is my savior, it grab anything until the next char outside of the () is reach.

Thank you
Mathias. is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 07:56.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode