ects/Object/constructor)
    2. [ ` Object.prototype.__proto__ ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/proto) Deprecated 
  13. Methods 
    1. [ ` Object.prototype.__defineGetter__() ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/__defineGetter__) Deprecated 
    2. [ ` Object.prototype.__defineSetter__() ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/__defineSetter__) Deprecated 
    3. [ ` Object.prototype.__lookupGetter__() ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/__lookupGetter__) Deprecated 
    4. [ ` Object.prototype.__lookupSetter__() ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/__lookupSetter__) Deprecated 
    5. [ ` Object.prototype.hasOwnProperty() ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty)
    6. [ ` Object.prototype.isPrototypeOf() ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isPrototypeOf)
    7. [ ` Object.prototype.propertyIsEnumerable() ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/propertyIsEnumerable)
    8. [ ` Object.prototype.toLocaleString() ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toLocaleString)
    9. [ ` Object.prototype.toString() ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString)
    10. [ ` Object.prototype.valueOf() ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf)

##  In this article

  * Try it 
  * Description 
  * Examples 
  * Specifications 
  * Browser compatibility 
  * See also 

#  RegExp.prototype.source

The **` source ` ** accessor property of [ ` RegExp ` ](/en-
US/docs/Web/JavaScript/Reference/Global_Objects/RegExp) instances returns a
string containing the source text of this regular expression, without the two
forward slashes on both sides or any flags.

##  Try it

##  Description

Conceptually, the ` source ` property is the text between the two forward
slashes in the regular expression literal. The language requires the returned
string to be properly escaped, so that when the ` source ` is concatenated
with a forward slash on both ends, it would form a parsable regex literal. For
example, for ` new RegExp("/") ` , the ` source ` is ` \\/ ` , because if it
generates ` / ` , the resulting literal becomes ` /// ` , which is a line
comment. Similarly, all [ line terminators ](/en-
US/docs/Web/JavaScript/Reference/Lexical_grammar#line_terminators) will be
escaped because line terminator _characters_ would break up the regex literal.
There's no requirement for other characters, as long as the result is
parsable. For empty regular expressions, the string ` (?:) ` is returned.

##  Examples

###  Using source

js

    
    
    const regex = /fooBar/gi;
    
    console.log(regex.source); // "fooBar", doesn't contain /.../ and "gi".
    

###  Empty regular expressions and escaping

js

    
    
    new RegExp().source; // "(?:)"
    
    new RegExp("\n").source === "\\n"; // true, starting with ES5
    

##  Specifications

Specification  
---  
[ ECMAScript Language Specification  
#  sec-get-regexp.prototype.source  ](https://tc39.es/ecma262/multipage/text-
processing.html#sec-get-regexp.prototype.source)  
  
##  Browser compatibility

BCD tables only load in the browser  with JavaScript enabled. Enable
JavaScript to view data.

##  See also

  * [ ` RegExp.prototype.flags ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/flags)

##  Help improve MDN

Was this page helpful to you?

Yes  No

[ Learn how to contribute
](https://github.com/mdn/content/blob/main/CONTRIBUTING.md "This will take you
to our contribution guidelines on GitHub.") .

This page was last modified on  Apr 12, 2023  by  [ MDN contributors ](/en-
US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/source/contributors.txt)
.

[ View this page on GitHub
](https://github.com/mdn/content/blob/main/files/en-
us/web/javascript/reference/global_objects/regexp/source/index.