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.
You can use a callback function, that look if a key matching the error code exists in your `Lang` object, and if so returns the value of that (and otherwise just the key itself, thereby doing no replacement, like so:

```
content.replace(/_err_([a-z_]+)/gi, function(fullmatch, key) {
  return Lang[key] ? Lang[key] : fullmatch;
});

```

The first parameter passed to the function will be the full match, and the second parameter `key` will just be that part grouped by the bracktes.

And then, if `Lang` contains a (non-falsy) value for `key`, that’ll be returned, otherwise just the `fullmatch` value, so that that part of the string gets “replaced” with itself.

See it in action here: <http://jsfiddle.net/VZVLt/1/>