Buffo Posted August 29, 2007 Share Posted August 29, 2007 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 Link to comment Share on other sites More sharing options...
xcal Posted August 29, 2007 Share Posted August 29, 2007 Global $array[4] = ['abc_01_xyz', 'abcd_32_xyz', 'ab_01_wxyz', 'def_ghi'] For $i = 0 To 3 $ret = StringRegExp($array[$i], '01|[a-z]_[a-z]', 0) If $ret Then ConsoleWrite(@LF & $array[$i]) Next ConsoleWrite(@LF) ConsoleWrite(@LF) How To Ask Questions The Smart Way Link to comment Share on other sites More sharing options...
Xenobiologist Posted August 29, 2007 Share Posted August 29, 2007 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 Link to comment Share on other sites More sharing options...
Buffo Posted August 29, 2007 Author Share Posted August 29, 2007 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.rarfilename.can.contain.dots.part02.rarfilename.can.contain.dots.part03.rarfilename.can.contain.dots.part04.rarfilename.can.contain.dots.part05.rarfilename.can.contain.dots.part06.rarfilename.can.contain.dots.part07.rarfilename.can.contain.dots.part08.rarfilename.can.contain.dots.part09.rarfilename.can.contain.dots.part10.rarfilename.can.contain.dots.part11.rarfilename.can.contain.dots.part12.rarfilename.with.part01.in.it.part1.rarfilename.with.part01.in.it.part2.rarfilename.can.contain.part.rarfilename.rarThe 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 Link to comment Share on other sites More sharing options...
randallc Posted August 29, 2007 Share Posted August 29, 2007 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 ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW Link to comment Share on other sites More sharing options...
Buffo Posted August 30, 2007 Author Share Posted August 30, 2007 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 Link to comment Share on other sites More sharing options...
randallc Posted August 30, 2007 Share Posted August 30, 2007 Unfortunatley that won't work.It works here for the data you gave! - just run my test script to see...Are you still not supplying the data in the same format you are testing?...best, randall ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW Link to comment Share on other sites More sharing options...
Buffo Posted August 30, 2007 Author Share Posted August 30, 2007 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: expandcollapse popupGlobal 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 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now