Find files that match the regex pattern -
i need find files match particular pattern in grails.
the files labeled "runid.started.xml". i'm looking find using following regex:
/(? <=\.)(.*?)(?=\.)/ i can find files need likit files match pattern. found few examples none seem work. latest:
new file (c:\\mydirectory\\test ).eachfilerecurse (files) { if (it.name ==~ /(? <=\.)(.*?)(?=\.)/){ println { println "nope" } this returns "nope"... i'm new grails i'm not sure i'm going wrong. regex seems correct in online regex tester may wrong.
==~ match operator. meaning string in question must exact match. , (? <=\.)(.*?)(?=\.) doesn't match "runid.started.xml". have 2 options:
- use search operator in if statement:
=~ - write regex exactly matches file names like:
\w*\.(\w+)\.\w*
Comments
Post a Comment