| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/pt-BR/docs/Web/JavaScript/Reference/Global_Objects/RegExp/toString | [Back] [Original] |
Get to know MDN better
Esta pgina foi traduzida do ingls pela comunidade. Saiba mais e junte-se comunidade MDN Web Docs.
This feature is well established and works across many devices and browser versions. Its been available across browsers since julho de 2015.
O mtodo toString() retorna uma string que representa uma expresso regular.
console.log(new RegExp("a+b+c"));
// Expected output: /a+b+c/
console.log(new RegExp("a+b+c").toString());
// Expected output: "/a+b+c/"
console.log(new RegExp("bar", "g").toString());
// Expected output: "/bar/g"
console.log(new RegExp("\n", "g").toString());
// Expected output (if your browser supports escaping): "/\n/g"
console.log(new RegExp("\\n", "g").toString());
// Expected output: "/\n/g"
toString();
Uma string representando o objeto dado.
O objeto RegExp subscreve o mtodo toString() do objeto
Object; ele no herda Object.prototype.toString().
Para objetos RegExp, o mtodo toString() retorna uma
representao da expresso regular como string.
O exemplo a seguir exibe o valor em string de um objeto RegExp
const myExp = new RegExp("a+b+c");
console.log(myExp.toString()); // logs '/a+b+c/'
const foo = new RegExp("bar", "g");
console.log(foo.toString()); // logs '/bar/g'
Introduzindo o ECMAScript 5, uma expresso regular vazia retorna a string "/(?:)/" e terminadores de linha como "\n" so utilizados
new RegExp().toString(); // "/(?:)/"
new RegExp("\n").toString() === "/\n/"; // verdadeiro, antes do ES5
new RegExp("\n").toString() === "/\\n/"; // verdadeiro, introduzindo o ES5
| Specification |
|---|
| ECMAScript 2027 LanguageSpecification # sec-regexp.prototype.tostring |
This page was last modified on 17 de fev. de 2025 by MDN contributors.
RegExpObject/FunctionObject.prototype.__defineGetter__()Object.prototype.__defineSetter__()Object.prototype.__lookupGetter__()Object.prototype.__lookupSetter__()Object.prototype.hasOwnProperty()Object.prototype.isPrototypeOf()Object.prototype.propertyIsEnumerable()Object.prototype.toLocaleString()Object.prototype.toString()Object.prototype.valueOf()Your blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |