ee.String.match
Matches a string against a regular expression. Returns a list of matching strings.
Usage | Returns |
---|
String.match(regex, flags) | List |
Argument | Type | Details |
---|
this: input | String | The string in which to search. |
regex | String | The regular expression to match. |
flags | String, default: "" | A string specifying a combination of regular expression flags, specifically one or more of: 'g' (global match) or 'i' (ignore case). |
Examples
var s = ee.String('ABCabc123');
print(s.match('')); // ""
print(s.match('ab', 'g')); // ab
print(s.match('ab', 'i')); // AB
print(s.match('AB', 'ig')); // ["AB","ab"]
print(s.match('[a-z]+[0-9]+')); // "abc123"
print(s.match('\\d{2}')); // "12"
// Use [^] to match any character except a digit.
print(s.match('abc[^0-9]', 'i')); // ["ABCa"]
Python setup
See the
Python Environment page for information on the Python API and using
geemap
for interactive development.
import ee
import geemap.core as geemap
s = ee.String('ABCabc123')
print(s.match('').getInfo()) # ""
print(s.match('ab', 'g').getInfo()) # ab
print(s.match('ab', 'i').getInfo()) # AB
print(s.match('AB', 'ig').getInfo()) # ['AB','ab']
print(s.match('[a-z]+[0-9]+').getInfo()) # 'abc123'
print(s.match('\\d{2}').getInfo()) # '12'
# Use [^] to match any character except a digit.
print(s.match('abc[^0-9]', 'i').getInfo()) # ['ABCa']
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-07-13 UTC.
[null,null,["Last updated 2024-07-13 UTC."],[[["The `String.match()` method searches a string for a specified regular expression and returns a list of matches."],["It accepts the input string, the regular expression pattern, and optional flags ('g' for global match and 'i' for case-insensitive search)."],["If a match is found, the method returns a list containing the matching substring(s); otherwise, it returns an empty list."],["You can use various regular expression patterns and flags to control the matching behavior, including character classes, quantifiers, and anchors."]]],["The `String.match()` function searches a string (`input`) for matches to a given regular expression (`regex`). It returns a list of matching strings. Optional flags (`flags`) modify the search, such as 'g' for global matching or 'i' for case-insensitive matching. The examples demonstrate various regex patterns and flag combinations. The function returns an empty string if the pattern is empty, or list of matching strings when successful. The examples cover the use case for Javascript and Python.\n"]]