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"]
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']