初歩的な質問で恐縮ですが、お分かりの方ご教授ください。

画像のパスの一部を書き換えるjsを書いてるんですが
ネットで調べてページすべての画像は↓で変更できるようになったのですが、
特定のclass(<div class="gallery">)の中にある<img>画像だけ書き換える時の書き方がわかりません。
jsマスターの方、ご教授ください。

window.onload = function() {
  var images = document.images;
  for (var i=0, n=images.length; i<n; i++) {
    var img = images[i];
    img.src = img.src.replace(/xxx/, 'xxx_s');
  }
};