Question: For some reason when I try to write through a pipe with fputc my program doesn't work; however, it works fine when I use the write system call. Here is the part of my code using fputc:

```
    FILE *input = fopen(argv[1], "rb");
    FILE *toSort = fdopen(ps_fd[1], "wb");
    /* close the side of pipe I am not going to use */
    close (ps_fd[0]);
    char temp;
    char buf[1];
    while ((temp=fgetc(input)) != EOF)
    {
        buf[0] = (char)temp;
        fputs(buf, toSort);
        buf[0] = '\0';
    }
    fputs(buf, toSort);
    close(ps_fd[1]);

```

Answer: 
A simple regex should do the trick:

```
var content = content.replace(/\b_err_(.+?)\b/g, function(match, errorName) {
    return Lang[errorName] || match;
});

```

This assumes that you do not want strings like `"blah_err_blah"` to be replaced, and defaults to not replacing the text if the error cannot be found in your `Lang` object.
```
var replace = function(str, object, regexp) { //if property not found string is not replaced
    return String(str).replace(regexp || (/\\?\{([^{}]+)\}/g), function(match, name) {
        return (object[name] != null) ? object[name] : match;
    });
}

```

This is a format function I've used in several projects thats quite efficient. Matches `{prop}` by default to {prop:'val'} but you can pass a regex for example maybe in your case `/_err_+\S/g` so it matches other tokens in your string.

So you can do:

```
var content ="Looks like you have {no_email} or {no_code} provided";
var Lang = {
    'no_email' : "No email",
    'no_code' : "No code"
}

var formatted = replace(content, lang);

```

Or for your original string stealing the other answers regex:

```
var formatted = replace(content, lang, /_err_([^\s]+)/g)

```