Java。用于解析FTP服务器列表的正则表达式。

时间:2022-06-21 00:34:24

I am having troubles with my regex to filter FTP server list to file/directory name and size. This is the regex I'm currently using (?m)^.{20}\\s*(\\d+).{14}(.*)$
So, using this to filter this list

我的regex有问题,无法将FTP服务器列表过滤为文件/目录名和大小。这是我目前使用的正则表达式(?)^ { 20 }。\ \ * \ \ d +。{ 14 }(. *)美元,用这个来过滤列表

drw-rw-rw- 1 ftp ftp                0 Mar 17 06:10 Tor Browser
-rw-rw-rw- 1 ftp ftp          1538814 Jun 26 00:23 setup.exe
-rw-rw-rw- 1 ftp ftp           142570 May 24 05:28 satellite A665-S6086.pdf


I will get Tor Browser, 0 and setup.exe, 1538814
which is what I actually wants but in a list of this format

我将得到Tor浏览器,0和设置。exe 1538814,这是我想要的但是在这个格式列表中

 -r-xr-xr-x  1 0  1001     4521014 May 23  2011 FileZilla_3.5.0_win32-setup.exenull
 dr-xr-xr-x  4 0  1001  1024 Mar  2 14:07 pubnull

I will get something like: ay 23 2011 FileZilla_3.5.0_win32-setup.exe, 1 and 14:07 pub ,1.
Is there a way i can make this regex works for both types?
Thank you

我将得到一些类似的东西:ay23 2011 FileZilla_3.5.0_win32-setup。exe, 1和14:07 pub,1。我是否有办法让这个regex对这两种类型都有效?谢谢你!

1 个解决方案

#1


3  

I would use the following:

我将使用以下方法:

Pattern regex = Pattern.compile(
    "(\\d+)        # File size           \n" +
    "\\s+          # Whitespace          \n" +
    "\\w{3}        # Month (3 letters)   \n" +
    "\\s+          # Whitespace          \n" +
    "\\d{1,2}      # Day (1 or 2 digits) \n" +
    "\\s+          # Whitespace          \n" +
    "[\\d:]{4,5}   # Time or year        \n" +
    "\\s+          # Whitespace          \n" +
    "(.*)          # Filename            \n" +
    "$             # End of line", 
    Pattern.MULTILINE | Pattern.COMMENTS);

#1


3  

I would use the following:

我将使用以下方法:

Pattern regex = Pattern.compile(
    "(\\d+)        # File size           \n" +
    "\\s+          # Whitespace          \n" +
    "\\w{3}        # Month (3 letters)   \n" +
    "\\s+          # Whitespace          \n" +
    "\\d{1,2}      # Day (1 or 2 digits) \n" +
    "\\s+          # Whitespace          \n" +
    "[\\d:]{4,5}   # Time or year        \n" +
    "\\s+          # Whitespace          \n" +
    "(.*)          # Filename            \n" +
    "$             # End of line", 
    Pattern.MULTILINE | Pattern.COMMENTS);