Sign in to follow this  
Followers 0
Buffo

Need StringRegExp help

8 posts in this topic

Hi!

I want to define a extract folder from a given full path archive.

Examples:

D:\Downloads\archiv.zip -> D:\Downloads\archiv

D:\Downloads\archiv.rar -> D:\Downloads\archiv

D:\Downloads\archiv.part01.rar -> D:\Downloads\archiv

Summarized: The name of the archive should be the extract path. Rar-archives could contain "partxx".

My regular expressions are (I tried two different with same result):

StringRegExp($sArchive, "(.*)(\.part\d{1,2}){0,1}\..{3}", 1)

StringRegExp($sArchive, "(.*)(\.part\d{1,2})?\..{3}", 1)

I started at the end: Always there is a 3 character long extension (zip, rar, ace,...) with a dot before. Then there could be.partxy before, and the rest is the searched substring.

The result returns the correct string in the first two examples, but if the string contains the .partxy substring the result is "D:\Downloads\archiv.part01". I would be lucky if anyone could give me th solution for my prob AND VERY IMPORTANT: Please explain, I don't know what should be wrong in my expressions :)

Thx a lot in advance.

Regards,

Buffo

Share this post


Link to post
Share on other sites



Why not just use _PathSplit?


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Let's start with a solution for your problem:

StringRegExp($sArchive, "(.*?)(\.part\d{1,2}){0,1}\..{3}", 1)

The only thing changed: adding the "?" to the first expression turns it into a non-greedy expression,

so it does not take ALL the characters it can get but instead takes the smallest possible fitting string.

Fiddled around with it using Regex Coach,

and it confuses me a little to see that the "(.*)" of your original expression would spare out the ".rar" part, but include the "partxx" string.

Expected it either to catch this one, too (whole string) or to stop at ".part". :)

Edited by Marc

It's my job to comfort the disturbed and to disturb the comfortable.

Share this post


Link to post
Share on other sites

@SmOke_N: That will not be the solution. Try to read my question again and you will see :P

@Marc: Thx a lot that's it! I tried to search with the smallest match but I put the question mark outside the brackets :D:)

I love this forum. Very competent people around. I'll be back with my next problem :D

Regards,

Buffo

Share this post


Link to post
Share on other sites

Another question again :whistle:

I want to match an archive filename with (if exists) "part"

$var = StringRegExp($archive, "(.*(\.part(?:\d{1,3}))?)\..{3}\z", 1)

1. $archive = test.rar -> result = test OK

2. $archive = test.part01.rar -> result = test.part01 (should be test.part)

The search pattern "(.*(\.part(?:\d{1,3}))?)\..{3}\z" means to me

.* = take all (until next match)

(\.part = match ".part" ...

(?:\d{1,3} = ...only if between 1 and 3 digits follows (don't return this digits)

))? = the "part\d{1,3}" must not exist

\..{3} = match a point with following three characters at the end of the string (fileext)

What is the mistake?

Regards,

Buffo

Share this post


Link to post
Share on other sites

@SmOke_N: That will not be the solution. Try to read my question again and you will see :whistle:

well, I think you should read the help file of _PathSplit() and StringSplit(), then you will see your solution!


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

Hi,

I dunno really get why and what you are trying to do, but the pattern yould work : \w+\.part

So long,

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

$sFileName = 'part'
$sPattern = "(?i)(.*?\." & $sFileName & ")\d{0,3}\..{3}$"
Negates the digits as you've requested, and shows the end result for both queries for what you've provided.


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0