Search code examples
c++boostboost-regex

Searching using regular expressions C++


I'm using Boost.Regex to achieve something like this: search for a "|" and then take the left part of the "|" and put it a string, same with the right part:

string s1;
string s2;
who | sort

After this s1 should be "who" and s2 shoudl be "sort".
If I remember good, it was posible in Python, how can I do it using regular expressions in Boost ?

Thank you.


Solution

  • #include <boost/algorithm/string.hpp>
    std::vector<std::string> strs;
    boost::split(strs, "string to split", boost::is_any_of("|"));
    

    Split a string in C++?