Input: `"some random text [[specialthing]] blah blah"`

Output: `"some random text ANOTHERTEXT blah blah"`

---

Goal:

Replace `[[specialthing]]` by what `myFunction('specialthing');` will return.

I already got a function that does exactly this without Regex but I was wondering if there would be an easier/better way to do that.

My code:

```
    data = "some random text [[specialthing]] blah blah";
    for(var i = 0 ; i < data.length ; i++){
        if(data[i] == '[' && data[i+1] == '['){
            var start = i;
            for(var j = start; j < data.length ; j++){
                if(data[j] == ']' && data[j+1] == ']'){
                    var strInBracket = data.slice(start+2,j);
                    var newStr = myFunction(strInBracket);
                    data = data.replace('\[\[' + strInBracket + '\]\]',newStr);
                }
            }
        }
    }

```

Solution:

```
    data = "some random text [[specialthing]] blah blah";

    var strInBracket = data.match(/([^\[]*)(..[^\]]*..)(.*)/)[2];
    var newStr = myFunction(strInBracket.slice(2,-2));
    data = data.replace(strInBracket,newStr);

```

I'm using javascript.

The solution doesn't need to be a regex.