Find most recent date in list
I'm using a 3rd party ETL tool with some FTP capabilities, but they're minimal (it's called Pentaho).
All I need to do is download the most recent file zip off of a ftp site. The site content appears as the following:
...
File:tfo.supplement.20120901.done 9/1/2012 3:48:00 AM
File:tfo.supplement.20120901.zip 421144 KB 9/1/2012 3:48:00 AM
File:tfo.supplement.20120904.done 9/4/2012 3:57:00 AM
File:tfo.supplement.20120904.zip 421794 KB 9/4/2012 3:57:00 AM
File:tfo.supplement.20120905.done 9/5/2012 3:28:00 AM
File:tfo.supplement.20120905.zip 421875 KB 9/5/2012 3:28:00 AM
So, in this case, I'd want the tfo.supplement.20120905.zip file.
The 3rd party tool only provides a get-file option that takes a folder and a regular expression. It will grab all files in the target FTP site folder matching the regular expression.
Someone told me that it is possible to make a regex that will actually compare the different matching options and output the maximum one. Eg take all tfo.supplement.* files ending in .zip and treat the date in the middle as an integer, pick the one with the largest integer.
I had no idea regex could support that kind of functionality. Can someone help me build an expression I can use in this use case?
Are you looking for something like this? >>
s/s(d+)/(d+)/(d{4})s/{$d = 10000*$3+100*$1+$2 if $d < 10000*$3+100*$1+$2}/eg;
Test this code here.
链接地址: http://www.djcxy.com/p/77078.html上一篇: 使用正则表达式来检查PHP中的特定模式
下一篇: 在列表中找到最近的日期