Question: **for those asking, the {0} allows selection of any one block within the sResult string separated by the | 0 is the first block** 

it needs to be dynamic for future expansion as that number will be configurable by users 

So I am working on a regex to extract 1 portion of a string, however while it matches the results return are not what is expected.

```
    std::string sResult = "MATCH_ME|BUT|NOT|ANYTHNG|ELSE";
    std::regex pattern("^(?:[^|]+[|]){0}([^|;]+)");
    std::smatch regMatch;

    std::regex_search(sResult, regMatch, pattern);
    if(regMatch[1].matched)
    {
      for( int i = 0; i < regMatch.size(); i++)
      {
           //SUBMATCH 0 = "MATCH_ME|BUT|NOT|ANYTHNG|ELSE"
           //SUBMATCH 1 = "BUT|NOT|ANYTHNG|ELSE"
        std::ssub_match sm = regMatch[i];
        bValid = strcmp(regMatch[i].str().c_str(), pzPoint->_ptrTarget->_pzTag->szOPCItem);
      }
    }

```

For some reason I cannot figure out the code to get me just the MATCH\_ME back so I can compare it to expected results list on the C++ side.

Anyone have any ideas on where I went wrong here.

Answer: 
It seems you're using regular expressions for what they haven't been designed for. You should first split your string at the delimiter `|` and apply regular expressions on the resulting tokens if you want to check them for validity.

By the way: The `std::regex` implementation in `libstdc++` seems to be buggy. I just did some tests and found that even simple patterns containing escaped pipe characters like `\\|` failed to compile throwing a `std::regex_error` with no further information in the error message (GCC 4.8.1).
Turns out the problem was on the C side in extracting the match, it had to be done more directly, below is the code that gets me exactly what I wanted out of the string so I can use it later. 

```
std::string sResult = "MATCH_ME|BUT|NOT|ANYTHNG|ELSE";
std::regex pattern("^(?:[^|]+[|]){0}([^|;]+)");
std::smatch regMatch;

std::regex_search(sResult, regMatch, pattern);
if(regMatch[1].matched)
{
   std::string theMatchedPortion = regMatch[1];
   //the issue was not with the regex but in how I was retrieving the results.
   //theMatchedPortion now equals "MATCH_ME" and by changing the number associated 
        with it I can navigate through the string
}

```