groovy - Regex 'find' returns 2 entries -


i have requirement list files in url , using jsoup based on question file names in format - mb-2014-04-13-07_12_22.log.2 question why variable 'file' inside .each method has 2 entries same value (mb-2014-04-13-07_12_22.log.2) whereas 'println filename' correctly prints once?

        def (doc,files, dirs) = [jsoup.connect(logfolder).get(),[],[]]         doc.select("body pre a").each { a->         def filename = a.attr('href')         println filename         (filename =~ /(.*?\.log(.*?)\.(\d?))/).each{file->             def fileurl = logfolder+file[0];             println fileurl;          }     } 

what gain from:

filename =~ /(.*?\.log(.*?)\.(\d?))/ 

is object of type matcher

groovy> println (filename =~ /(.*?\.log(.*?)\.(\d?))/)  java.util.regex.matcher[pattern=(.*?\.log(.*?)\.(\d?)) region=0,28 lastmatch=] 

and file pointing list of groups of regex:

[mb-2014-04-13-07_12_22.log.2, mb-2014-04-13-07_12_22.log.2, , 2] 

first element first pair of parenthesis, second element second pair of parenthesis , on (zero element whole expression).

some more info regex in groovy here


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -