groovy regexpression
How to get fi开发者_开发技巧le name from these lines using groovy .
File file = new File(SOURCE_FILE_NAME).eachLine{line->
println line
}
getting line like this :
/usr/local/
/usr/local/testing.groovy
/usr/local/picture.jpg
expecting output:
testing.groovy
picture.jpg
thanks
File file = new File(SOURCE_FILE_NAME).eachLine{ path ->
println org.apache.commons.lang.StringUtils.substringAfterLast(path, "/")
}
I don't know about groovy, but the regex you're looking for would be[^/]+$
println (new File(yourString).name)
This should work.
also (no external deps)
["/usr/local", "/usr/local/testing.groovy",
"/usr/local/picture.jpg"].each { item->
def pat = item =~ /(\w*\/)*(.*)/
if(pat.matches()) {
println pat.group(2)
}
}
精彩评论