Question: `std::regex_replace` (Added in C++ 11) replaces all the occurrences. How can I make it replace only the first occurrence?

Answer: 
If the `flags` parameter to [`std::regex_replace`](http://en.cppreference.com/w/cpp/regex/regex_replace) contains `std::regex_constants::format_first_only`, only the first match is replaced.

```
std::regex_replace("12 34",
                   std::regex(R"(\d+)"),
                   "num",
                    std::regex_constants::format_first_only);

```

[stribizhev](https://stackoverflow.com/users/3832970/stribizhev) kindly provided a [working example](http://ideone.com/PvzQgf).
I found the solution myself. Posting for others if they face the same issue.
Add:

`std::tr1::regex_constants::format_first_only`

to replace only the first occurrence as the fourth argument to `regex_replace`