请在下面找到我的代码。我正在尝试遍历文件和目录并打印出与正则表达式的所有匹配项:(&)(.+?\b)
但这似乎不起作用(它返回一个空字符串)。我哪里做错了?
import groovy.io.FileType
class FileExample {
static void main(String[] args) {
def list = []
def dir = new File("*path to dir*")
dir.eachFileRecurse (FileType.FILES) { file ->
list << file.name;
def s= "${file.text}";
def w = s.toString();
w.readLines().grep(~/(&)(.+?\b)/)
}
}
}