公告:凡是在 
2025 年 4 月 15 日前註冊使用 Earth Engine 的非商業專案,都必須
驗證非商業用途資格,才能繼續存取。如未在 2025 年 9 月 26 日前完成驗證,存取權可能會暫停。
  
        
 
       
     
  
  
  
    
  
  
  
    
      ee.String.match
    
    
      
    
    
      
      透過集合功能整理內容
    
    
      
      你可以依據偏好儲存及分類內容。
    
  
  
      
    
  
  
  
  
  
    
  
  
    
    
    
  
  
根據規則運算式比對字串。傳回相符字串的清單。
| 用量 | 傳回 | 
|---|
| String.match(regex, flags) | 清單 | 
| 引數 | 類型 | 詳細資料 | 
|---|
| 這個: input | 字串 | 要搜尋的字串。 | 
| regex | 字串 | 要比對的規則運算式。 | 
| flags | 字串,預設值為「""」 | 字串,用於指定規則運算式旗標的組合,具體來說是一或多個:'g' (全域比對) 或 'i' (忽略大小寫)。 | 
  
  
  範例
  
    
  
  
    
    
  
  
  
  
    
    
    
      程式碼編輯器 (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"]
  
    
  
  
    
  
  
  
  
    
  
    
  Python 設定
  請參閱 
    Python 環境頁面,瞭解 Python API 和如何使用 geemap 進行互動式開發。
  import ee
import geemap.core as geemap
  
    
    
      Colab (Python)
    
    
  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']
  
  
  
  
  
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
  上次更新時間:2025-10-24 (世界標準時間)。
  
  
  
    
      [null,null,["上次更新時間:2025-10-24 (世界標準時間)。"],[],["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"]]