Sign in to follow this  
Followers 0
Buffo

StringRegExp

8 posts in this topic

Hi!

Today there is a problem which I cannot solve alone.

The following example strings are given (a few letters, underscore, number or not, underscore and a few letters):

abc_01_xyz

abcd_32_xyz

ab_01_wxyz

def_ghi

I want to match the whole line but only if it contains 01 or it does NOT contain a number.

Can you help me?

Thx in advance.

Rgeards,

Buffo

Share this post


Link to post
Share on other sites

Hi,

or this way :-)

Global $array[4] = ['abc_01_xyz', 'abcd_32_xyz', 'ab_01_wxyz', 'def_ghi']

For $i = 0 To 3
    $ret = StringRegExp($array[$i], '01|[\D]_[\D]', 0)
    If $ret Then ConsoleWrite(@LF & $array[$i])
Next
ConsoleWrite(@LF)

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

Many thx for your feedback :)

But it's not so easy as I thought. I forgot that there are other possibilities that have to match.

My intention is to find in a filelist all RAR-archives which are the first of a multipart archive or only single parts.

Filelist:

filename.can.contain.dots.part01.rar

filename.can.contain.dots.part02.rar

filename.can.contain.dots.part03.rar

filename.can.contain.dots.part04.rar

filename.can.contain.dots.part05.rar

filename.can.contain.dots.part06.rar

filename.can.contain.dots.part07.rar

filename.can.contain.dots.part08.rar

filename.can.contain.dots.part09.rar

filename.can.contain.dots.part10.rar

filename.can.contain.dots.part11.rar

filename.can.contain.dots.part12.rar

filename.with.part01.in.it.part1.rar

filename.with.part01.in.it.part2.rar

filename.can.contain.part.rar

filename.rar

The bold marked lines should match.

Sorry for prompting only a example where I experimented with. But now this is the real task ;)

The complicated on this is that the strings without .part1, part01, part001 and so on should only match.

Another solution out there? ;)

Regards,

Buffo

Share this post


Link to post
Share on other sites

Hi,

Modifying pevious;

this seems to work, but may not be the best way;

Global $array[4] = ['filename.can.contain.dots.part01.rar', 'filename.rar', 'filename.can.contain.part1.rar', 'filename.can.contain.dots.part07.rar']

For $i = 0 To 3
    $ret = StringRegExp($array[$i], '01|part1.|[^[0-9]]*\.rar', 0)
    If $ret Then ConsoleWrite(@LF & $array[$i])
Next
ConsoleWrite(@LF)
Randall

Share this post


Link to post
Share on other sites

Unfortenatley that won't work.

I try again to explain (the second line in topic title "How to exlude?").

Imho the pattern should be something like this:

(.+(\.part{0,3}1|NOT\.part\d{1,4})\.rar\z)

The meaning:

Match all .partxxx1 or all where .partxxxx is not contained before .rar at the end of line (where xxx can be 0 to 3 digits).

How is it possible to integrate the NOT with Regex?

The ^ is only for groups. I tried with (squared) brackets but it won't work :)

Thx in advance.

Regards,

Buffo

Share this post


Link to post
Share on other sites

For the examples I gave it works fine, yes :)

But there are other possibilities given:

Only a few examples which match although it shouldn't:

file01.part03.rar

file_test01.part02.rar

file.part1.onlyfortest.part03.rar

This one doesn't match although it should:

filename.part001.rar

My script is now a bit more complicated because I solved it with further queries:

Global Const $PATH = "F:\"

While 1
    $var = FindFile()
    If $var = -1 Then Exit
    ...
    Sleep(25)
WEnd

Func FindFile()
    Local $oFileList
    Local $sFile, $sValue
    
    $oFileList = FileFindFirstFile($PATH & "*.*")
    If $oFileList = -1 Then Return -1
    
    While 1
        $sFile = FileFindNextFile($oFileList)
        If @error Then 
            $sValue = -1
            ExitLoop
        EndIf
        
        If Not StringInStr(FileGetAttrib($sFile), "D") Then
            
            If StringRegExp($sFile, "\.part0{0,3}1\.rar\z", 0) = 1 Then 
                ...
                $sValue = $sFile
                ExitLoop
            Else
                If StringRegExp($sFile, "\.part\d{1,4}\.rar\z", 0) = 0 And StringRegExp($sFile, "\.rar\z", 0) = 1 Then 
                    ...
                    $sValue = $sFile
                    ExitLoop    
                Else
                    $sValue = -1
                EndIf
            EndIf
        EndIf
    WEnd
    Return $sValue
EndFunc

This script exactly does what I need. I hoped it could be easier with only one regex. But now it works - that's the most important ;)

Thx all for your help ;)

Regards,

Buffo

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