소문자를 대문자로 변환하기
const string = "hello";
const uppercase = string.replace(/[a-z]/g, (char) => char.toUpperCase());
console.log(uppercase); // "HELLO"
소문자, 숫자, 공백문자를 제외한 모든 문자를 대문자로 변환하기
const uppercase = string.replace(/[^a-z0-9\s]/gi, (char) => char.toUpperCase());
소문자를 제외한 모든 문자 제거하기
const onlyLowercase = string.replace(/[^a-z]/g, "");
대문자와 소문자 뒤바꾸기
const string = "HeLLo WorLD";
const swapped = string.replace(/[a-z]/gi, (char) => (char === char.toUpperCase()) ? char.toLowerCase() : char.toUpperCase());
console.log(swapped); // "hEllO wOrld"