Revision 488281 of RegExp.prototype.toString()

  • Revision slug: Web/JavaScript/Reference/Global_Objects/RegExp/toString
  • Revision title: RegExp.prototype.toString()
  • Revision id: 488281
  • Created:
  • Creator: fscholz
  • Is current revision? No
  • Comment

Revision Content

{{JSRef("Global_Objects", "RegExp")}}

Summary

The toString() method returns a string representing the regular expression.

Syntax

regexObj.toString()

Parameters

None.

Description

The {{jsxref("Global_Objects/RegExp", "RegExp")}} object overrides the toString method of the {{jsxref("Global_Objects/Object", "Object")}} object; it does not inherit {{jsxref("Object.prototype.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/"

Specifications

Specification Status Comment
ECMAScript 3rd Edition. Implemented in JavaScript 1.1 Standard Initial definition.
{{SpecName('ES5.1', '#sec-15.9.5.2', 'RegExp.prototype.toString')}} {{Spec2('ES5.1')}}  
{{SpecName('ES6', '#sec-regexp.prototype.tostring', 'RegExp.prototype.toString')}} {{Spec2('ES6')}}  

Browser compatibility

{{ CompatibilityTable() }}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support {{ CompatVersionUnknown() }} {{ CompatVersionUnknown() }} {{ CompatVersionUnknown() }} {{ CompatVersionUnknown() }} {{ CompatVersionUnknown() }}
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support {{ CompatVersionUnknown() }} {{ CompatVersionUnknown() }} {{ CompatVersionUnknown() }} {{ CompatVersionUnknown() }} {{ CompatVersionUnknown() }} {{ CompatVersionUnknown() }}

See also

  • {{jsxref("Object.prototype.toString()")}}

Revision Source

<div>
 {{JSRef("Global_Objects", "RegExp")}}</div>
<h2 id="Summary" name="Summary">Summary</h2>
<p>The <code><strong>toString()</strong></code> method returns a string representing the regular expression.</p>
<h2 id="Syntax" name="Syntax">Syntax</h2>
<pre class="syntaxbox">
<var>regexObj</var>.toString()</pre>
<h3 id="Parameters" name="Parameters">Parameters</h3>
<p>None.</p>
<h2 id="Description" name="Description">Description</h2>
<p>The {{jsxref("Global_Objects/RegExp", "RegExp")}} object overrides the <code>toString</code> method of the {{jsxref("Global_Objects/Object", "Object")}} object; it does not inherit {{jsxref("Object.prototype.toString()")}}. For <code>RegExp</code> objects, the <code>toString</code> method returns a string representation of the regular expression.</p>
<h2 id="Examples" name="Examples">Examples</h2>
<h3 id="Example:_Using_toString" name="Example:_Using_toString">Example: Using <code>toString</code></h3>
<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>
<h2 id="Specifications">Specifications</h2>
<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
  <tr>
   <td>ECMAScript 3rd Edition. Implemented in JavaScript 1.1</td>
   <td>Standard</td>
   <td>Initial definition.</td>
  </tr>
  <tr>
   <td>{{SpecName('ES5.1', '#sec-15.9.5.2', 'RegExp.prototype.toString')}}</td>
   <td>{{Spec2('ES5.1')}}</td>
   <td>&nbsp;</td>
  </tr>
  <tr>
   <td>{{SpecName('ES6', '#sec-regexp.prototype.tostring', 'RegExp.prototype.toString')}}</td>
   <td>{{Spec2('ES6')}}</td>
   <td>&nbsp;</td>
  </tr>
 </tbody>
</table>
<h2 id="Browser_compatibility">Browser compatibility</h2>
<p>{{ CompatibilityTable() }}</p>
<div id="compat-desktop">
 <table class="compat-table">
  <tbody>
   <tr>
    <th>Feature</th>
    <th>Chrome</th>
    <th>Firefox (Gecko)</th>
    <th>Internet Explorer</th>
    <th>Opera</th>
    <th>Safari</th>
   </tr>
   <tr>
    <td>Basic support</td>
    <td>{{ CompatVersionUnknown() }}</td>
    <td>{{ CompatVersionUnknown() }}</td>
    <td>{{ CompatVersionUnknown() }}</td>
    <td>{{ CompatVersionUnknown() }}</td>
    <td>{{ CompatVersionUnknown() }}</td>
   </tr>
  </tbody>
 </table>
</div>
<div id="compat-mobile">
 <table class="compat-table">
  <tbody>
   <tr>
    <th>Feature</th>
    <th>Android</th>
    <th>Chrome for Android</th>
    <th>Firefox Mobile (Gecko)</th>
    <th>IE Mobile</th>
    <th>Opera Mobile</th>
    <th>Safari Mobile</th>
   </tr>
   <tr>
    <td>Basic support</td>
    <td>{{ CompatVersionUnknown() }}</td>
    <td>{{ CompatVersionUnknown() }}</td>
    <td>{{ CompatVersionUnknown() }}</td>
    <td>{{ CompatVersionUnknown() }}</td>
    <td>{{ CompatVersionUnknown() }}</td>
    <td>{{ CompatVersionUnknown() }}</td>
   </tr>
  </tbody>
 </table>
</div>
<h2 id="See_Also" name="See_Also">See also</h2>
<ul>
 <li>{{jsxref("Object.prototype.toString()")}}</li>
</ul>
Revert to this revision