RegExp.prototype.toSource()

Obsolete
This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it.

The toSource() method returns a string representing the source code of the object.

Syntax

regexObj.toSource()

Return value

A string representing the source code of the given RegExp object.

Description

The toSource() method returns the following values:

  • For the built-in RegExp object, toSource() returns the following string indicating that the source code is not available:
    function RegExp() {
        [native code]
    }
    
  • For instances of RegExp, toSource() returns a string representing the source code.

This method is usually called internally by JavaScript and not explicitly in code.

Specifications

Not part of any standard. Implemented in JavaScript 1.3.

Browser compatibility

Update compatibility data on GitHub
DesktopMobileServer
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung InternetNode.js
toSource
Non-standard
Chrome No support NoEdge No support NoFirefox Full support 1
Notes
Full support 1
Notes
Notes Starting in Firefox 74, toSource() is no longer available for use by web content. It is still allowed for internal and privileged code.
IE No support NoOpera No support NoSafari No support NoWebView Android No support NoChrome Android No support NoFirefox Android Full support 4Opera Android No support NoSafari iOS No support NoSamsung Internet Android No support Nonodejs No support No

Legend

Full support  
Full support
No support  
No support
Non-standard. Expect poor cross-browser support.
Non-standard. Expect poor cross-browser support.
See implementation notes.
See implementation notes.

See also