Anuncio: Todos los proyectos no comerciales registrados para usar Earth Engine antes del
15 de abril de 2025 deben
verificar su elegibilidad no comercial para mantener el acceso a Earth Engine.
ee.String.replace
Organiza tus páginas con colecciones
Guarda y categoriza el contenido según tus preferencias.
Devuelve una nueva cadena con algunas o todas las coincidencias de un patrón reemplazadas.
Uso | Muestra |
---|
String.replace(regex, replacement, flags) | String |
Argumento | Tipo | Detalles |
---|
esta: input | String | Es la cadena en la que se realizará la búsqueda. |
regex | String | Es la expresión regular con la que se debe coincidir. |
replacement | String | Es la cadena que reemplaza la subcadena coincidente. |
flags | Cadena, valor predeterminado: "" | Es una cadena que especifica una combinación de marcas de expresiones regulares, específicamente una o más de las siguientes: "g" (coincidencia global) o "i" (ignorar mayúsculas y minúsculas). |
Ejemplos
Editor de código (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
Configuración de Python
Consulta la página
Entorno de Python para obtener información sobre la API de Python y el uso de geemap
para el desarrollo interactivo.
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
Salvo que se indique lo contrario, el contenido de esta página está sujeto a la licencia Atribución 4.0 de Creative Commons, y los ejemplos de código están sujetos a la licencia Apache 2.0. Para obtener más información, consulta las políticas del sitio de Google Developers. Java es una marca registrada de Oracle o sus afiliados.
Última actualización: 2025-07-26 (UTC)
[null,null,["Última actualización: 2025-07-26 (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```"]]