Regex matches the first file in rar archive file installed in Python

I need to unzip all the files in the directory, and for this I need to find the first file in the set. I am currently doing this using a bunch of if statements and loops. Can I do this with regex?

Here is the list of files that I need to map:

yes.rar
yes.part1.rar
yes.part01.rar
yes.part001.rar
yes.r01
yes.r001

They should NOT be matched:

no.part2.rar
no.part02.rar
no.part002.rar
no.part011.rar
no.r002
no.r02

I found a similar regex in this thread, but it seems that Python does not support variable length scans. A single-line regex will be complicated, but I am documenting it well and that is not a problem. This is just one of those problems that you beat your heap, more.

Thanks in advance guys.

:)

+2
3

. , , . :

^((?!\.part(?!0*1\.rar$)\d+\.rar$).)*\.(?:rar|r?0*1)$

, :

^((?:(?!\.part\d+\.rar$).)*)\.(?:(?:part0*1\.)?rar|r?0*1)$
+2

, , . , .

RAR , , , RAR.

HEAD_FLAGS -:
2

0x0100 - ( RAR 3.0 )

, RAR, , , . , .


. , . , . . - .

+5

, ?

yes.r01

:.rar .

This is bla.rar, bla.r00, and then only bla.r01. You will probably extract the files twice if .r01 and .rar are matched as the first archive.

yes.r001

.r001 does not exist. Do you mean .001 files that WinRAR supports? After .r99, this is .s00. If it exists, then someone manually renamed the files.

Theoretically, matching by file name should be as reliable as matching by flag 0x0100 to find the first archive.

0
source

Source: https://habr.com/ru/post/1731675/


All Articles