title: C++ split string using a list of words as separators
body: <p>I would like to split a string like this one</p>
  
  <pre><code>“this1245is@g$0,therhsuidthing345”
  </code></pre>
  
  <p>using a list of words like the one bellow</p>
  
  <pre><code>{“this”, “is”, “the”, “thing”}
  </code></pre>
  
  <p>into this list</p>
  
  <pre><code>{“this”, “1245”, “is”, “@g$0,”, “the”,  “rhsuid”, “thing”, “345”}
  // ^--------------^---------------^------------------^-- these were the delimiters
  </code></pre>
  
  <p>The delimiters are allowed to appear more than once in the string to split, and it can be done using regular expressions</p>
  
  <p>The precedence is in the order in which the delimiters appear in the array</p>
  
  <p>The platform I'm developing for has no support for the Boost library </p>
  
  <p><strong>Update</strong></p>
  
  <p>This is what I have for the moment</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;regex&gt;
  
  int main ()
  {
      std::string s ("this1245is@g$0,therhsuidthing345");
      std::string delimiters[] = {"this", "is", "the", "thing"};
  
      for (int i=0; i&lt;4; i++) {
          std::string delimiter =  "(" + delimiters[i] + ")(.*)";
          std::regex e (delimiter);   // matches words beginning by the i-th delimiter
  
          // default constructor = end-of-sequence:
          std::sregex_token_iterator rend;
  
          std::cout &lt;&lt; "1st and 2nd submatches:";
          int submatches[] = { 1, 2 };
          std::sregex_token_iterator c ( s.begin(), s.end(), e, submatches );
          while (c!=rend) std::cout &lt;&lt; " [" &lt;&lt; *c++ &lt;&lt; "]";
          std::cout &lt;&lt; std::endl;
      }
  
      return 0;
  }
  </code></pre>
  
  <p>output:</p>
  
  <pre><code>1st and 2nd submatches:[this][x1245fisA@g$0,therhsuidthing345]
  1st and 2nd submatches:[is][x1245fisA@g$0,therhsuidthing345]
  1st and 2nd submatches:[the][rhsuidthing345]
  1st and 2nd submatches:[thing][345]
  </code></pre>
  
  <p>I think I need to make some recursive thing to call on each iteration</p>