From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../global_objects/regexp/source/index.html | 69 ++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 files/ja/web/javascript/reference/global_objects/regexp/source/index.html (limited to 'files/ja/web/javascript/reference/global_objects/regexp/source/index.html') diff --git a/files/ja/web/javascript/reference/global_objects/regexp/source/index.html b/files/ja/web/javascript/reference/global_objects/regexp/source/index.html new file mode 100644 index 0000000000..ea0b05887c --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/regexp/source/index.html @@ -0,0 +1,69 @@ +--- +title: RegExp.prototype.source +slug: Web/JavaScript/Reference/Global_Objects/RegExp/source +tags: + - JavaScript + - Property + - Prototype + - Reference + - RegExp + - Regular Expressions +translation_of: Web/JavaScript/Reference/Global_Objects/RegExp/source +--- +
{{JSRef}}
+ +

source プロパティは、正規表現オブジェクトのソーステキストを含む {{jsxref("String")}} を返します。これには、両端の 2 つのスラッシュやフラグは含まれません。

+ +
{{EmbedInteractiveExample("pages/js/regexp-prototype-source.html")}}
+ + + +
{{js_property_attributes(0, 0, 1)}}
+ +

+ +

source の使用

+ +
var regex = /fooBar/ig;
+
+console.log(regex.source); // "fooBar", /.../ と "ig" は含まれません。
+
+ +

空の正規表現とエスケープ

+ +

ECMAScript 5 から、source プロパティは空の正規表現に対して空文字を返さなくなりました。代わりに、(?:) 文字列を返します。加えて、 ("\n" のような) 行区切りはエスケープされます。

+ +
new RegExp().source; // "(?:)"
+
+new RegExp('\n').source === '\n';  // ES5 以前で、true
+new RegExp('\n').source === '\\n'; // ES5 から、true
+
+ +

仕様書

+ + + + + + + + + + + + +
仕様書
{{SpecName('ESDraft', '#sec-get-regexp.prototype.source', 'RegExp.prototype.source')}}
+ +

ブラウザーの互換性

+ +
+ + +

{{Compat("javascript.builtins.RegExp.source")}}

+
+ +

関連情報

+ + -- cgit v1.2.3-54-g00ecf