const url = 'http://example.com';
// 'http://' 또는 'https://'로 시작하는지 검사한다.
/^https?:\/\//.test(url); // ture
const fileName = 'index.html';
// 'html'로 끝나는지 검사한다.
/html$/.test(fileName); // true
[...] 바깥의 ^은 문자열의 시작을 $는 문자열의 마지막을 \d는 숫자를 의미하고 +는 앞선 패턴이 최소 한 번 이상 반복되는 문자열을 의미한다
const a = '12345';
// 숫자로만 이루어진 문자열인지 검사
/^\d+$/.test(a); // true
const mail = 'abcdef@gmail.com';
/^[0-9a-zA-Z]([-_\.]?[0-9a-zA-Z])*@[0-9a-zA-Z]([-_\.]?[0-9a-zA-Z])*\.[a-zA-Z]{2,3}$/.test(mail); // true
const id = 'abc123';
// 알파벳 대소문자 또는 숫자로 시작하고 끝나며 4~10자리인지 검사
/^[A-Za-z0-9]{4,10}$/.test(id); // true
const a = ' am';
/^[\s]+/.test(a); // true
const phone = '010-1234-5678';
/^\d{3}-\d{3,4}-\d{4}$/.test(phone); // true
const target = 'abc#123';
/[^A-Za-z0-9]/gi.test(targetStr); //true
// 다른 방식
/[\{\}\[\]\/?.,;:|\)*~`!^\-_+<>@\#$%&\\\=\(\'\"]/gi.test(target); //true
// 특수 문자 제거
target.replace(/[^A-Za-z0-9]/gi, ''); // abc1233