StrongCurlyStilt

var input1 = "p[tkfcsxlmnr]|t[pkfcsxlmnr]|k[ptfcslmnr]|f[ptkcsxlmnr]|c[ptkflmnr]|s[ptkfxlmnr]|x[ptfslmnr]|b[dgvjzlmnr]|d[bgvjzlmnr]|g[bdvjzlmnr]|v[bdgjzlmnr]|j[bdgvlmnr]|z[bdgvlmnr]|l[ptkfcsxbdgvjzmnr]|m[ptkfcsxbdgvjlnr]|n[ptkfcsxbdgvjzlmr]|r[ptkfcsxbdgvjzlmn]";

var input2 = "[bcfgkmpsvx][lr]|[cs][fkmnpt]|d[jrz]|[jz][bdgmv]|t[crs]";

function findPairs(input) {
    var res = [];
    input.split("|").forEach(function (group) {
        var firsts = group[0] === "[" ? group.slice(1, group.indexOf("]")) : group[0];
        var seconds = group.slice(group.lastIndexOf("[") + 1, -1);
        for (var i = 0; i < firsts.length; i++) {
            for (var j = 0; j < seconds.length; j++) {
                res.push(firsts[i] + seconds[j]);
            }
        }
    });
    return res;
}

var firstsAndSeconds = findPairs(input1);
var secondsAndThirds = findPairs(input2);

firstsAndSeconds.sort();
secondsAndThirds.sort();

var threes = [];

firstsAndSeconds.forEach(function (part1) {
    var thirds = [];
    secondsAndThirds.forEach(function (part2) {
        if (part1[1] === part2[0]) {
            thirds.push(part2[1]);
        }
    });
    if (!thirds.length) {
        return;
    }
    if (thirds.length === 1) {
        threes.push(part1 + thirds[0]);
    } else {
        threes.push(part1 + "(?:" + thirds.join("|") + ")");
    }
});

console.log("(?:" + threes.join("|") + ")");