Caesars Cipher, how to use regex to add in spaces and other non-characters?

I am pretty much solved this algorithm challenge, but I do not know how to use regex to add in the spaces.
Here is my code :slight_smile:

/*

requirment: if input is a letter => shift 13 places then output the result
						if input is a space, output space

*/
function rot(str) {
    const ALPHABET = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"];
    var input_num = 0;
    var output_num = 0;
    var output = "";
    //outer loop for str
    for (let i = 0; i < str.length; i++) {
        //inner loop for ALPHABET
        for (let j = 0; j < ALPHABET.length; j++) {
            if (ALPHABET[j] === str[i]) {
                input_num = j;
                output_num = input_num + 13;
                if (output_num > 25) {
                    output_num = output_num - 26;
                }
                output = output + ALPHABET[output_num];
            }
        }
    }
    console.log(output);
}

rot("SERR PBQR PNZC");

Nevermind I figured it out.

function rot13(str) { // LBH QVQ VG!
      const ALPHABET = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"];
    var input_num = 0;
    var output_num = 0;
    var output = "";
    //outer loop for str
    for (let i = 0; i < str.length; i++) {
        //if string[i] is not a char then add it in.
        if (str[i].toUpperCase() == str[i].toLowerCase() ) {
        	output += str[i];
        } else {
            //inner loop for ALPHABET
            for (let j = 0; j < ALPHABET.length; j++) {
                if (ALPHABET[j] === str[i]) {
                    input_num = j;
                    output_num = input_num + 13;
                    if (output_num > 25) {
                        output_num = output_num - 26;
                    }
                    output = output + ALPHABET[output_num];
                }
            }
        }
    }
    str = output;
  return str;
}

// Change the inputs below to test
console.log(rot13("GUR DHVPX OEBJA SBK WHZCF BIRE GUR YNML QBT."));