blob: 83a963dae649c118688064de67a416b5838e2ab8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
---
title: Symbol.search
slug: Web/JavaScript/Reference/Global_Objects/Symbol/search
tags:
- ECMAScript 2015
- JavaScript
- Property
- Symbol
translation_of: Web/JavaScript/Reference/Global_Objects/Symbol/search
---
<div>{{JSRef}}</div>
<p><strong><code>Symbol.search</code></strong> はウェルノウンシンボルで、正規表現に一致する文字列内の位置を返すメソッドを指定します。この関数は {{jsxref("String.prototype.search()")}} メソッドによって呼び出されます。</p>
<p>詳しくは、 {{jsxref("RegExp.@@search", "RegExp.prototype[@@search]()")}} と {{jsxref("String.prototype.search()")}} を参照してください。</p>
<div>{{EmbedInteractiveExample("pages/js/symbol-search.html")}}</div>
<div class="hidden">このデモのソースファイルは GitHub リポジトリに格納されています。デモプロジェクトに協力したい場合は、 <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> をクローンしてプルリクエストを送信してください。</div>
<div>{{js_property_attributes(0,0,0)}}</div>
<h2 id="Examples" name="Examples">例</h2>
<h3 id="Custom_string_search" name="Custom_string_search">独自の文字列検索</h3>
<pre class="brush: js notranslate">class caseInsensitiveSearch {
constructor(value) {
this.value = value.toLowerCase();
}
[Symbol.search](string) {
return string.toLowerCase().indexOf(this.value);
}
}
console.log('foobar'.search(new caseInsensitiveSearch('BaR')));
// expected output: 3</pre>
<h2 id="Specifications" name="Specifications">仕様書</h2>
<table class="standard-table">
<thead>
<tr>
<th scope="col">仕様書</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{SpecName('ESDraft', '#sec-symbol.search', 'Symbol.search')}}</td>
</tr>
</tbody>
</table>
<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2>
<div class="hidden">このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> をチェックアウトしてプルリクエストを送信してください。</div>
<p>{{Compat("javascript.builtins.Symbol.search")}}</p>
<h2 id="See_also" name="See_also">関連情報</h2>
<ul>
<li>{{jsxref("Symbol.match")}}</li>
<li>{{jsxref("Symbol.replace")}}</li>
<li>{{jsxref("Symbol.split")}}</li>
<li>{{jsxref("RegExp.@@search", "RegExp.prototype[@@search]()")}}</li>
</ul>
|