Send feedback
ee.String.split
Stay organized with collections
Save and categorize content based on your preferences.
Splits a string on a regular expression, Returning a list of strings.
Usage Returns String. split (regex, flags )
List
Argument Type Details this: string
String The string to split. regex
String A regular expression to split on. If regex is the empty string, then the input string is split into individual characters. flags
String, default: "" A string specifying the regular expression flag: 'i' (ignore case).
Examples
Code Editor (JavaScript)
var s = ee . String ( 'aBAbcD' );
print ( s . split ( 'Ab' )); // ["aB","cD"]
// 'i' tells split to ignore case.
print ( s . split ( 'ab' , 'i' )); // ["","","cD"]
// Split on 'b' or 'c'
print ( s . split ( '[bc]' , 'i' )); // ["a","A","","D"]
// Split on 'BA' or 'c'
print ( s . split ( '(BA|c)' )); // ["a","b","D"]
var s = ee . String ( 'a,b,cdee f,g' );
// ["a",",","b",",","c","d","e","e"," ","f",",","g"]
print ( s . split ( '' ));
print ( s . split ( ' ' )); // ["a,b,cdee","f,g"]
print ( s . split ( '[[:space:]]' )); // ["a,b,cdee","f,g"]
print ( s . split ( ',' )); // ["a","b","cdee f","g"]
print ( s . split ( 'ee' )); // ["a,b,cd"," f,g"]
// Split on any lower case letter.
print ( s . split ( '[a-z]' )); // ["",",",",","","",""," ",","]
// ^ as the first character in [] excludes.
print ( s . split ( '[^a-z]' )); // ["a","b","cdee","f","g"]
// Splitting on characters that are special to split.
var s = ee . String ( 'a.b*c?d' );
print ( s . split ( '\\.' )); // ["a","b*c?d"]
print ( s . split ( '[*]' )); // ["a.b","c?d"]
print ( s . split ( '[?]' )); // ["a.b*c","d"]
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
Colab (Python)
s = ee . String ( 'aBAbcD' )
print ( s . split ( 'Ab' ) . getInfo ()) # ['aB', 'cD']
# 'i' tells split to ignore case.
print ( s . split ( 'ab' , 'i' ) . getInfo ()) # ['', '', 'cD']
# Split on 'b' or 'c'
print ( s . split ( '[bc]' , 'i' ) . getInfo ()) # ['a', 'A', '', 'D']
# Split on 'BA' or 'c'
print ( s . split ( '(BA|c)' ) . getInfo ()) # ['a', 'b', 'D']
s = ee . String ( 'a,b,cdee f,g' )
# ['a', ',', 'b', ',', 'c', 'd', 'e', 'e', ' ', 'f', ',', 'g']
print ( s . split ( '' ) . getInfo ())
print ( s . split ( ' ' ) . getInfo ()) # ['a,b,cdee', 'f,g']
print ( s . split ( '[[:space:]]' ) . getInfo ()) # ['a,b,cdee', 'f,g']
print ( s . split ( ',' ) . getInfo ()) # ['a', 'b', 'cdee f', 'g']
print ( s . split ( 'ee' ) . getInfo ()) # ['a,b,cd', ' f,g']
# Split on any lower case letter.
print ( s . split ( '[a-z]' ) . getInfo ()) # ['', ',', ',', '', '', '', ' ', ',']
# ^ as the first character in [] excludes.
print ( s . split ( '[^a-z]' ) . getInfo ()) # ['a', 'b', 'cdee', 'f', 'g']
# Splitting on characters that are special to split.
s = ee . String ( 'a.b*c?d' )
print ( s . split ( ' \\ .' ) . getInfo ()) # ['a', 'b*c?d']
print ( s . split ( '[*]' ) . getInfo ()) # ['a.b', 'c?d']
print ( s . split ( '[?]' ) . getInfo ()) # ['a.b*c', 'd']
Send feedback
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.
Need to tell us more?
[[["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 2024-07-13 UTC."],[[["`String.split()` divides a string into a list of substrings based on a provided regular expression."],["The function accepts an optional `flags` argument, supporting 'i' for case-insensitive splitting."],["If the regular expression is an empty string, the input string is split into individual characters."],["Special characters within the regular expression can be escaped using a backslash."]]],[]]