RegExp.prototype.toString()

  • Revision slug: JavaScript/Reference/Global_Objects/RegExp/toString
  • Revision title: toString
  • Revision id: 87940
  • Created:
  • Creator: Sevenspade
  • Is current revision? No
  • Comment Reverted to earlier version; 12 words added, 5 words removed

Revision Content

 

Summary

Returns a string representing the specified object.

Method of RegExp
Implemented in: JavaScript 1.1, NES2.0
ECMA Version: ECMA-262, Edition 3

Syntax

regexp.toString()

Parameters

None.

Description

The RegExp object overrides the toString method of the Object object; it does not inherit Object.toString. For RegExp objects, the toString method returns a string representation of the regular expression.

Examples

Example: Using toString

The following example displays the string value of a RegExp object:

myExp = new RegExp("a+b+c");
alert(myExp.toString());       // displays "/a+b+c/"

See Also

Object.prototype.toString

{{ languages( { "ja": "ja/Core_JavaScript_1.5_Reference/Global_Objects/RegExp/toString", "pl": "pl/Dokumentacja_j\u0119zyka_JavaScript_1.5/Obiekty/RegExp/toString" } ) }}

Revision Source

<p>
 </p>
<h3 name="Summary"> Summary </h3>
<p>Returns a string representing the specified object.
</p>
<table class="fullwidth-table">
<tbody><tr>
<td class="header" colspan="2">Method of <a href="en/Core_JavaScript_1.5_Reference/Global_Objects/RegExp">RegExp</a></td>
</tr>
<tr>
<td>Implemented in:</td>
<td>JavaScript 1.1, NES2.0</td>
</tr>
<tr>
<td>ECMA Version:</td>
<td>ECMA-262, Edition 3</td>
</tr>
</tbody></table>
<h3 name="Syntax"> Syntax </h3>
<p><code><em>regexp</em>.toString()</code>
</p>
<h3 name="Parameters"> Parameters </h3>
<p>None.
</p>
<h3 name="Description"> Description </h3>
<p>The <code>RegExp</code> object overrides the <code>toString</code> method of the <code><a href="en/Core_JavaScript_1.5_Reference/Global_Objects/Object">Object</a></code> object; it does not inherit <code><a href="en/Core_JavaScript_1.5_Reference/Global_Objects/Object/toString">Object.toString</a></code>. For <code>RegExp</code> objects, the <code>toString</code> method returns a string representation of the regular expression.
</p>
<h3 name="Examples"> Examples </h3>
<h4 name="Example:_Using_toString"> Example: Using <code>toString</code> </h4>
<p>The following example displays the string value of a <code>RegExp</code> object:
</p>
<pre>myExp = new RegExp("a+b+c");
alert(myExp.toString());       // displays "/a+b+c/"
</pre>
<h3 name="See_Also"> See Also </h3>
<p><a href="en/Core_JavaScript_1.5_Reference/Global_Objects/Object/toString">Object.prototype.toString</a>
</p>{{ languages( { "ja": "ja/Core_JavaScript_1.5_Reference/Global_Objects/RegExp/toString", "pl": "pl/Dokumentacja_j\u0119zyka_JavaScript_1.5/Obiekty/RegExp/toString" } ) }}
Revert to this revision