title: C++11 regex matching capturing group multiple times
body: <p>Could someone please help me to extract the text between the : and the ^ symbols using a JavaScript (ECMAScript) regular expression in C++11.  I do not need to capture the <code>hw-descriptor</code> itself - but it does have to be present in the line in order for the rest of the line to be considered for a match.  Also the <code>:p....^</code>, <code>:m....^</code> and <code>:u....^</code> can arrive in any order and there has to be at least 1 present.</p>
  
  <p>I tried using the following regular expression:</p>
  
  <pre><code>static const std::regex gRegex("(?:hw-descriptor)(:[pmu](.*?)\\^)+", std::regex::icase);
  </code></pre>
  
  <p>against the following text line:</p>
  
  <pre><code>"hw-descriptor:pTEXT1^:mTEXT2^:uTEXT3^"
  </code></pre>
  
  <p>Here is the code which posted on a <strong><a href="http://coliru.stacked-crooked.com/a/ef175ee3830226d0" rel="nofollow noreferrer">live coliru</a></strong>.  It shows how I attempted to solve this problem, however I am only getting 1 match.  I need to see how to extract each of the potential 3 matches corresponding to the p m or u characters described earlier.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;vector&gt;
  #include &lt;regex&gt;
  
  int main()
  {
      static const std::regex gRegex("(?:hw-descriptor)(:[pmu](.*?)\\^)+", std::regex::icase);
      std::string foo = "hw-descriptor:pTEXT1^:mTEXT2^:uTEXT3^";
      // I seem to only get 1 match here, I was expecting 
      // to loop through each of the matches, looks like I need something like 
      // a pcre global option but I don't know how.
      std::for_each(std::sregex_iterator(foo.cbegin(), foo.cend(), gRegex), std::sregex_iterator(), 
          [&amp;](const auto&amp; rMatch) {
              for (int i=0; i&lt; static_cast&lt;int&gt;(rMatch.size()); ++i) {
                  std::cout &lt;&lt; rMatch[i] &lt;&lt; std::endl;
              }
          });
  }
  </code></pre>
  
  <p>The above program gives the following output:</p>
  
  <pre><code>g++ -std=c++14 -O2 -Wall -pedantic -pthread main.cpp &amp;&amp; ./a.out
  hw-descriptor:pTEXT1^:mTEXT2^:uTEXT3^
  :uTEXT3^
  TEXT3
  </code></pre>