How to replace a character in a string but only if it occurs within a delimited substring?
<p>I would like to replace a character with another character in a string but only when the character occurs within a delimited substring of the string. For example, for the string:</p>

<blockquote>
  <p>b[b]abc[abc]bbb[bbb]</p>
</blockquote>

<p>I would like to change "b" to "x" but only if it is within square brackets "[...]". Thus, the desired result is the string:</p>

<blockquote>
  <p>b[x]abc[axc]bbb[xxx]</p>
</blockquote>

<p>My preference would be a sed or bash solution because they are in my comfort zone, but any solution that would work for Mac OS X would be fine. From searching, it seems that this can be accomplished with sed using negative lookahead and negative lookbehind, but I don't believe those features are available on the Mac version of sed.</p>