Home

function: replace


replace(string: string, pattern: RegExp, string, replacement: function, string): string

Replaces matches for `pattern` in `string` with `replacement`. **Note:** This method is based on [`String#replace`](https://mdn.io/String/replace).

Example(s):

replace('Hi Fred', 'Fred', 'Barney')
// => 'Hi Barney'

Params:

Name Type Attribute Description
string The string to modify.
pattern The pattern to replace.
replacement The match replacement.

Returns:

string

  {
    "comment": "/**\r\n * Replaces matches for `pattern` in `string` with `replacement`.\r\n *\r\n * **Note:** This method is based on\r\n * [`String#replace`](https://mdn.io/String/replace).\r\n *\r\n * @since 4.0.0\r\n * @category String\r\n * @param {string} [string=''] The string to modify.\r\n * @param {RegExp|string} pattern The pattern to replace.\r\n * @param {Function|string} replacement The match replacement.\r\n * @returns {string} Returns the modified string.\r\n * @see truncate, trim\r\n * @example\r\n *\r\n * replace('Hi Fred', 'Fred', 'Barney')\r\n * // => 'Hi Barney'\r\n */",
    "meta": {
        "range": [
            548,
            681
        ],
        "filename": "replace.js",
        "lineno": 19,
        "path": "C:\\Users\\beaujeup\\projects\\jsdoc-template\\examples\\lodash\\lodash-repo",
        "code": {
            "id": "astnode100007776",
            "name": "replace",
            "type": "FunctionDeclaration",
            "paramnames": [
                "args"
            ]
        },
        "vars": {
            "string": "replace~string"
        }
    },
    "description": "Replaces matches for `pattern` in `string` with `replacement`.\r\r**Note:** This method is based on\r[`String#replace`](https://mdn.io/String/replace).",
    "since": "4.0.0",
    "tags": [
        {
            "originalTitle": "category",
            "title": "category",
            "text": "String",
            "value": "String"
        }
    ],
    "params": [
        {
            "type": {
                "names": [
                    "string"
                ]
            },
            "optional": true,
            "defaultvalue": "''",
            "description": "The string to modify.",
            "name": "string"
        },
        {
            "type": {
                "names": [
                    "RegExp",
                    "string"
                ]
            },
            "description": "The pattern to replace.",
            "name": "pattern"
        },
        {
            "type": {
                "names": [
                    "function",
                    "string"
                ]
            },
            "description": "The match replacement.",
            "name": "replacement"
        }
    ],
    "returns": [
        {
            "type": {
                "names": [
                    "string"
                ]
            },
            "description": "Returns the modified string."
        }
    ],
    "see": [
        "truncate, trim"
    ],
    "examples": [
        "replace('Hi Fred', 'Fred', 'Barney')\r// => 'Hi Barney'"
    ],
    "name": "replace",
    "longname": "replace",
    "kind": "function",
    "scope": "global",
    "___id": "T000002R000712",
    "___s": true,
    "filepath": "replace.js"
}