Объявление : Все некоммерческие проекты, зарегистрированные для использования Earth Engine до
15 апреля 2025 года, должны
подтвердить некоммерческое право на сохранение доступа к Earth Engine.
ee.String.replace
Оптимизируйте свои подборки
Сохраняйте и классифицируйте контент в соответствии со своими настройками.
Возвращает новую строку, в которой заменены некоторые или все совпадения шаблона.
Использование | Возврат | String. replace (regex, replacement, flags ) | Нить |
Аргумент | Тип | Подробности | это: input | Нить | Строка, в которой следует производить поиск. |
regex | Нить | Регулярное выражение для сопоставления. |
replacement | Нить | Строка, которая заменяет совпавшую подстроку. |
flags | Строка, по умолчанию: "" | Строка, определяющая комбинацию флагов регулярного выражения, а именно один или несколько из: «g» (глобальное совпадение) или «i» (без учета регистра) |
Примеры
Редактор кода (JavaScript)
print(ee.String('abc-abc').replace('abc', 'X')); // X-abc
print(ee.String('abc-abc').replace('abc', 'X', 'g')); // X-X
print(ee.String('abc-abc').replace('abc', '', 'g')); // -
print(ee.String('aBc-Abc').replace('abc', 'Z', 'i')); // Z-Abc
print(ee.String('aBc-Abc').replace('abc', 'Z', 'ig')); // Z-Z
Настройка Python
Информацию об API Python и использовании geemap
для интерактивной разработки см. на странице «Среда Python» .
import ee
import geemap.core as geemap
Colab (Python)
print(ee.String('abc-abc').replace('abc', 'X').getInfo()) # X-abc
print(ee.String('abc-abc').replace('abc', 'X', 'g').getInfo()) # X-X
print(ee.String('abc-abc').replace('abc', '', 'g').getInfo()) # -
print(ee.String('aBc-Abc').replace('abc', 'Z', 'i').getInfo()) # Z-Abc
print(ee.String('aBc-Abc').replace('abc', 'Z', 'ig').getInfo()) # Z-Z
Если не указано иное, контент на этой странице предоставляется по лицензии Creative Commons "С указанием авторства 4.0", а примеры кода – по лицензии Apache 2.0. Подробнее об этом написано в правилах сайта. Java – это зарегистрированный товарный знак корпорации Oracle и ее аффилированных лиц.
Последнее обновление: 2025-07-24 UTC.
[null,null,["Последнее обновление: 2025-07-24 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```"]]