This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

RegExp.prototype.compile()

Deprecated

Avoid using this feature in new projects. The compile() method duplicates behavior of the RegExp() constructor and it exists only for backwards compatibility. This feature may be a candidate for removal from web standards or browsers.

참고 : compile() 메서드는 호환성을 위해서만 명시되어 있습니다. compile()을 사용하면 변경 불가능한 정규식 소스와 플래그가 변경 가능하므로 사용자의 예상을 빗나갈 수 있습니다. 대신 RegExp() 생성자를 사용하여 새 정규식 객체를 생성할 수 있습니다.

RegExp 인스턴스의 compile() 메서드는 RegExp 객체가 이미 생성된 후 새로운 소스와 플래그를 사용하여 정규식을 다시 컴파일하는 데 사용됩니다.

구문

js
compile(pattern, flags)

매개변수

pattern

정규 표현식 텍스트

flags

플래그 값의 조합.

반환 값

없음 (undefined).

예제

compile() 사용하기

다음 예제는 새로운 패턴과 새로운 플래그를 사용하여 정규식을 다시 컴파일하는 방법을 보여 줍니다.

js
const regexObj = new RegExp("foo", "gi");
regexObj.compile("new foo", "g");

명세서

Specification
ECMAScript® 2027 Language Specification
# sec-regexp.prototype.compile

브라우저 호환성

같이 보기