Reputation: 129
I need to find all files that match a particular pattern in grails.
The files will be labeled as "runid.started.xml". So I'm looking to find all using the following regex:
/(? <=\.)(.*?)(?=\.)/
I can find all files but I need to likit it to files the match the pattern. I found a few examples but none seem to work. This is the latest:
New File (c:\\mydirectory\\test ).eachFileRecurse (Files)
{
if (it.name ==~ /(? <=\.)(.*?)(?=\.)/){
println it
{
println "nope"
}
This returns "nope"... I'm very new to grails so I'm not sure where I'm going wrong. My regex seems correct in an online regex tester but I may be wrong.
Upvotes: 0
Views: 1070
Reputation: 38919
==~
is a match operator. Meaning the string in question must be an exact match. And (? <=\.)(.*?)(?=\.)
doesn't match "runid.started.xml". So you have two options:
=~
\w*\.(\w+)\.\w*
Upvotes: 1