new RegExp('표현', '옵션')
new RegExp('[a-z]', 'gi')
/표현/옵션
/[a-z]/gi
<예시>
1. 생성자함수를 통한 정규표현식 생성
RegExp라는 자바스크립트 전역객체 생성 후 두개의 인수 추가
기본적으로 제일 처음에 찾아진 'the'라는 단어만 배열로 만들어줌
const regexp = new RegExp('the', '')
console.log(str.match(regexp)) //0: "the"
g플래그 사용(대소문자 구분)
const regexp = new RegExp('the', 'g')
console.log(str.match(regexp)) //(2) ["the", "the"]
gi플래그 사용(대소문자 구분 안함)
const regexp = new RegExp('the', 'gi')
console.log(str.match(regexp)) //(3) ["the", "The", "the"]
2. 리터럴방식으로 정규표현식 생성
const regexp = /the/gi
console.log(str.match(regexp)) //(3) ["the", "The", "the"]