Announcement: All noncommercial projects registered to use Earth Engine before April 15, 2025 must verify noncommercial eligibility to maintain Earth Engine access.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2023-10-06 UTC."],[[["\u003cp\u003eThe \u003ccode\u003ereplace()\u003c/code\u003e method returns a new string with instances of a given pattern replaced by a specified replacement string.\u003c/p\u003e\n"],["\u003cp\u003eIt accepts a regular expression or a string to define the pattern to be replaced and the replacement string.\u003c/p\u003e\n"],["\u003cp\u003eOptional flags can be used to control the behavior of the replacement, such as performing a global replacement ('g') or ignoring case ('i').\u003c/p\u003e\n"],["\u003cp\u003eThe method is available for Earth Engine String objects in both JavaScript and Python environments.\u003c/p\u003e\n"]]],["The `String.replace()` method replaces substrings within a string. It takes a `regex` (pattern), `replacement` string, and optional `flags`. The input string is searched for the `regex` pattern, and matched substrings are replaced by the `replacement`. Flags, like 'g' for global or 'i' for case-insensitive matching, modify the replacement behavior. The output is the modified string, the original string is not modified. The function operates the same for Javascript and Python.\n"],null,["# ee.String.replace\n\nReturns a new string with some or all matches of a pattern replaced.\n\n\u003cbr /\u003e\n\n| Usage | Returns |\n|-------------------------------------------------|---------|\n| String.replace`(regex, replacement, `*flags*`)` | String |\n\n| Argument | Type | Details |\n|---------------|---------------------|-------------------------------------------------------------------------------------------------------------------------------------|\n| this: `input` | String | The string in which to search. |\n| `regex` | String | The regular expression to match. |\n| `replacement` | String | The string that replaces the matched substring. |\n| `flags` | String, default: \"\" | A string specifying a combination of regular expression flags, specifically one or more of: 'g' (global match) or 'i' (ignore case) |\n\nExamples\n--------\n\n### Code Editor (JavaScript)\n\n```javascript\nprint(ee.String('abc-abc').replace('abc', 'X')); // X-abc\nprint(ee.String('abc-abc').replace('abc', 'X', 'g')); // X-X\nprint(ee.String('abc-abc').replace('abc', '', 'g')); // -\nprint(ee.String('aBc-Abc').replace('abc', 'Z', 'i')); // Z-Abc\nprint(ee.String('aBc-Abc').replace('abc', 'Z', 'ig')); // Z-Z\n```\nPython setup\n\nSee the [Python Environment](/earth-engine/guides/python_install) page for information on the Python API and using\n`geemap` for interactive development. \n\n```python\nimport ee\nimport geemap.core as geemap\n```\n\n### Colab (Python)\n\n```python\nprint(ee.String('abc-abc').replace('abc', 'X').getInfo()) # X-abc\nprint(ee.String('abc-abc').replace('abc', 'X', 'g').getInfo()) # X-X\nprint(ee.String('abc-abc').replace('abc', '', 'g').getInfo()) # -\nprint(ee.String('aBc-Abc').replace('abc', 'Z', 'i').getInfo()) # Z-Abc\nprint(ee.String('aBc-Abc').replace('abc', 'Z', 'ig').getInfo()) # Z-Z\n```"]]