Question: I am trying to change some values in my json file but it has no effect in the json file even though it prints the changes I have made below.

The json file:
--------------

```
{
"schemaVersion":1,
"array":[  
  { //values...
  },
  { //the relevant values..
    "id":"stackoverflow",
    "visible":true,
  }
 ]
} 

```

The json file is valid I just wrote the relevant things.

Boost code:
-----------

```
boost::property_tree::ptree doc;
string test = dir_path.string();
boost::property_tree::read_json(test, doc);

BOOST_FOREACH(boost::property_tree::ptree::value_type& framePair2, doc.get_child("array")){
   if (!framePair2.second.get<std::string>("id").compare("stackoverflow")){
        cout << framePair2.second.get<std::string>("id") << endl;
        cout << framePair2.second.get<std::string>("visible") << endl;
        framePair2.second.put<string>("visible", "false");
        cout << framePair2.second.get<std::string>("visible") << endl;
   }

```

The output:
-----------

```
stackoverflow //which is fine
true          //which is also fine
false         //which is exactly what I changed and need

```

The problem:
------------

There are no changes in the json file **even** though it prints a success change via `framePair2.second.put<string>("visible", "false");` and I don't understand why.

How can it be that it prints `false` **after** i use *put* method and in the json file it is still `true` ? Do I need to save the json file ? if so, what is the command for it using boost ?

Any help would be appreciated.

Thank you.

Answer: 
You can use `Regex.Matches` and concatenate each matches result. Just pick one you like the most.

```
//Sadly, we can't extend the Regex class
public class RegExp
{
    //usage : RegExp.Filter("50% of 50% is 25%", @"[0-9]+\%")
    public static string Filter(string input, string pattern)
    {
        return Regex.Matches(input, pattern).Cast<Match>()
            .Aggregate(string.Empty, (a,m) => a += m.Value);
    }
}

public static class StringExtension
{
    //usage : "50% of 50% is 25%".Filter(@"[0-9]+\%")
    public static string Filter(this string input, string pattern)
    {
        return Regex.Matches(input, pattern).Cast<Match>()
            .Aggregate(string.Empty, (a,m) => a += m.Value);
    }
}

```
I do not understand your reasoning why you want to use replace. Why go that way in the first place? There are methods in the `Regex` class that allow you to precisely get all the desired matches. Your roundabout way at getting to your solution I find is pointless.

Just use `Matches()` to collect the matches. You could then join them into the string that you wanted.

```
var str = "50% of 50% is 25%";
var re = new Regex(@"\d+%");
var ms = re.Matches(str);
var values = ms.Cast<Match>().Select(m => m.Value);
var joined = String.Join("", values); // "50%50%25%"

```