[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/RegExp/toString [Back]  [Original]

RegExp.prototype.toString() - JavaScript | MDN

MDN Web Docs

View in English Always switch to English

RegExp.prototype.toString()

Baseline

20157

toString() RegExp

console.log(new RegExp("a+b+c"));
// : /a+b+c/

console.log(new RegExp("a+b+c").toString());
// : "/a+b+c/"

console.log(new RegExp("bar", "g").toString());
// : "/bar/g"

console.log(new RegExp("\n", "g").toString());
// : "/\n/g"

console.log(new RegExp("\\n", "g").toString());
// : "/\n/g"

js
toString()

RegExp toString() Object Object.prototype.toString() RegExp toString()

source flags /source/flags toString() ()

toString()

RegExp

js
const myExp = new RegExp("a+b+c");
console.log(myExp.toString()); // '/a+b+c/'

const foo = new RegExp("bar", "g");
console.log(foo.toString()); // '/bar/g'

toString() source "/(?:)/" \n

js
new RegExp().toString(); // "/(?:)/"

new RegExp("\n").toString() === "/\\n/"; // true

ECMAScript 2027 LanguageSpecification
# sec-regexp.prototype.tostring


Web Proxy Viewer  |  New URL  |  Original Page