AI-generated Key Takeaways
-
The
String.matchmethod matches a string against a regular expression and returns a list of matching strings. -
It takes a regular expression string and optional flags ('g' for global, 'i' for ignore case) as arguments.
-
The method can be used to find specific patterns within a string, as demonstrated by various examples in JavaScript and Python.
| 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
Code Editor (JavaScript)
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"]
import ee import geemap.core as geemap
Colab (Python)
s = ee . String ( 'ABCabc123' ) display ( s . match ( '' )) # "" display ( s . match ( 'ab' , 'g' )) # ab display ( s . match ( 'ab' , 'i' )) # AB display ( s . match ( 'AB' , 'ig' )) # ['AB','ab'] display ( s . match ( '[a-z]+[0-9]+' )) # 'abc123' display ( s . match ( ' \\ d {2} ' )) # '12' # Use [^] to match any character except a digit. display ( s . match ( 'abc[^0-9]' , 'i' )) # ['ABCa']

