Groovy eachMatch()方法
处理每个正则表达式组(参见下一节)匹配的给定String的子字符串。
句法
void eachMatch(String regex, Closure clos)
参数
- Regex – The string expression to search for
- Closure – optional closure
返回值
无返回值。
例子
下面是一个使用这个方法的例子 -
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