Groovy - eachMatch()



為給定字串處理每個正則表示式組(請參見下一部分)匹配的子字串。

語法

void eachMatch(String regex, Closure clos)

引數

  • 正則表示式 - 要搜尋的字串表示式
  • 閉包 - 可選閉包

返回值

無返回值。

示例

以下是使用此方法的一個示例 −

class Example {
   static void main(String[] args) {
      String s = "HelloWorld";
      
      s.eachMatch(".") {
         ch -> println ch
      }
   }
}

當我們執行以上程式時,將獲得以下結果 −

H 
e 
l 
l 
o 
W 
o 
r 
l 
d
groovy_strings.htm
廣告
© . All rights reserved.