Regex to match the first file in a rar archive file set in Python
Posted
by mridang
on Stack Overflow
See other posts from Stack Overflow
or by mridang
Published on 2010-03-29T12:41:18Z
Indexed on
2010/03/29
12:43 UTC
Read the original article
Hit count: 490
I need to uncompress all the files in a directory and for this I need to find the first file in the set. I'm currently doing this using a bunch of if statements and loops. Can i do this this using regex?
Here's a list of files that i need to match:
yes.rar
yes.part1.rar
yes.part01.rar
yes.part001.rar
yes.r01
yes.r001
These 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 on this thread but it seems that Python doesn't support varible length lookarounds. A single line regex would be complicated but I'll document it well and it's not a problem. It's just one of those problems you beat your heap up, over.
Thanks in advance guys.
:)
© Stack Overflow or respective owner