开发者

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)
    }  
  }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜