「(x)」は、正規表現 x をグループ化します。
グループ化することで正規表現の中に別の表現を組み込むことができ、パターンが見やすくなります。
// 検索対象文字列
var str1 = "The earth";
var str2 = "the earth";
// 検索実行および結果出力
document.write("「The earth」からの抽出結果: ", str1.match(/(T|t)he/));
document.write("<br>「the earth」からの抽出結果: ", str2.match(/(T|t)he/));
// 検索対象文字列
var str = "abCdefGhiJabcdefg";
// 検索実行および結果出力
document.write("検索結果: ", str.search(/[A-Z]([a-z]).*\1/));
document.write("<br>抽出結果: ", str.match(/[A-Z]([a-z]).*\1/));
document.write("<br>置換結果: ", str.replace(/[A-Z]([a-z]).*\1/, "zzz"));
// 検索対象文字列
var str = "TAG12345";
// 検索実行および結果出力
document.write("検索結果: ", str.search(/([A-Z])+([0-9]+)/));
document.write("<br>抽出結果: ", str.match(/([A-Z]+)([0-9]+)/));
document.write("<br>置換結果: ", str.replace(/([A-Z]+)([0-9]+)/, "tag" + RegExp.$2));
document.write("<br>RegExp.$1: ", RegExp.$1);
document.write("<br>RegExp.$2: ", RegExp.$2);