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() コンストラクターを使用して新しい正規表現オブジェクトを構築してください。
compile() は RegExp インスタンスのメソッドで、 RegExp オブジェクトが既に作成された後、新しいソースとフラグで正規表現を再コンパイルするために使用します。
構文
js
compile(pattern, flags)
引数
返値
なし (undefined)。
例
>compile() の使用
次の例では、新しいパターンとフラグで正規表現を再コンパイルする方法を示します。
js
const regexObj = /foo/gi;
regexObj.compile("new foo", "g");
仕様書
| 仕様書 |
|---|
| ECMAScript® 2027 Language Specification> # sec-regexp.prototype.compile> |