1. 패턴 매칭

1) 캡처 그룹 (abc)

예제: 이름 분리하기

const myName = 'Ted Blue';
const regexName = /(\\w+) (\\w+)/;
const matchName = myName.match(regexName);
console.log(matchName);
console.log(matchName[1]);
console.log(matchName[2]);

match.png

2) 비캡처 그룹 (?:abc)

예제: 선택적 표현 매칭

http:// 또는 https://를 선택적으로 매치하지만 저장하지 않는 경우

const url = '<https://www.example.com>';
const regexUrl = /(?:https?:\\/\\/)?(www\\.\\w+\\.\\w+)/;
const matchUrl = url.match(regexUrl); // 일치할 경우 해당 표현식의 배열 형태로 값 반환
console.log(matchUrl);
console.log(matchUrl[1]); // www.example.com

match2.png

2. 긍정 및 부정의 전방탐색(lookahead)