Advert
thomasl
Active Members-
Posts
62 -
Joined
-
Last visited
thomasl's Achievements
Wayfarer (2/7)
0
Reputation
-
I haven't been here for a pretty long time but another user told me the other day that these files are not available anymore at the Autoit3 site. Not sure what bright soul deleted them (and why). Anyway, I have recompiled the stuff and put on my own site. Unfortunately I don't use AutoIt any longer, so I can't test this. See http://thomaslauer.com/download/Perlau3.zip or http://thomaslauer.com/download/Perlau3_perl58.zip See also http://thomaslauer.com/comp/Calling_Perl_from_AHK_or_AU3 for more details. -- cheers thomasl
-
New version with two changes: a) the $switch parameter can be a regular expression; a non-processed switch in $args now produces an error condition. Code for the UDF (file ParseCmdLine.au3): #include-once Func _If2($b,$t,$f) If $b Then Return $t Return $f EndFunc Func IsSwitch($cl,$switch) If StringLeft($switch,1)<>"^" Then $switch="^("&$switch&")" Local $r=StringRegExp($cl,$switch,1) If @Error=0 Then Return StringLen($r[0]) If @Error=1 Then Return 0 Return -1 EndFunc ;============================================================================== ; ; Name: _ParseCmdLine(), v1.01 ; Description: parses command line switches ; Parameter(s): $cl: a copy of $CmdLine (or another suitably initialised array) ; $args is an array with the command line arguments ; each entry in $args is a string with 4 parts, separated by a | : "type|switch|var|default" ; "type" is either b for a boolean or s for a string switch ; "switch" is what the user has to type on the command line (can be a simple regular expression) ; "var" is the AU3 variable (w/o the $) that will hold the result (needs not be declared) ; "default" is the default initialiser for "var" ; "default" is optional: if it's missing a boolean (ie "type" b) comes back false, a string (s) empty ; $switch is the switch character (default "-") ; $cs=1 means switches are case-sensitive (default not case-sensitive) ; Requirement(s): AutoIt ; Return Value(s): on success - returns 1, $cl is trimmed to hold only unprocessed entries ; on failure - returns 0 ; @error is 1 if either $cl or $args is not an array ; @error is 2 if there's an error in $args; @extended points to the entry in question ; @error is 3 if there's an error in $cl; @extended points to the entry in question ; @error is 4 if there's an unprocessed switch left in $cl; @extended points to the entry in question ; @error is 5 if the regular expression in $switch is invalid ; Author(s): thomasl ; ;============================================================================== Func _ParseCmdLine(ByRef $cl,$args,$switch="-",$cs=0) Local $i,$j,$a,$v,$s,$l If Not IsArray($cl) And Not IsArray($args) Then Return SetError(1,0,0) For $i=0 To UBound($args)-1 ; outer loop over all args $a=StringSplit($args[$i],"|") Switch $a[0] Case 3 $v=_If2($a[1]="b",False,"") ; use defaults Case 4 $v=_If2($a[1]="b",$a[4]="True",$a[4]) ; use initialiser Case Else Return SetError(2,$i,0) EndSwitch Assign($a[3],$v,2) ; assign value in case the switch is not encountered If $cs=0 Then $a[2]=StringLower($a[2]) For $j=1 To $cl[0] ; inner loop over command line args If $cl[$j]="" Then ContinueLoop $l=IsSwitch($cl[$j],($switch)) If $l=-1 Then Return SetError(5,0,0) If $l>0 Then $s=StringMid($cl[$j],$l+1,StringLen($a[2])) If $cs=0 Then $s=StringLower($s) If $s==$a[2] Then ; and switch string $s=StringMid($cl[$j],$l+StringLen($a[2])+1) If $a[1]="b" Then ; boolean? If $s<>"" Then Return SetError(3,$j,0) Assign($a[3],_If2($v,False,True)) Else ; string Assign($a[3],$s) EndIf $cl[$j]="" ; clear this entry EndIf EndIf Next Next $j=1 For $i=1 To $cl[0] ; clean up $cl[] If $cl[$i]<>"" Then If IsSwitch($cl[$i],($switch))>0 Then Return SetError(4,$i,0) If $i>$j Then $cl[$j]=$cl[$i] $cl[$i]="" EndIf $j+=1 EndIf Next $cl[0]=$j-1 Return SetError(0,0,1) ; home and dry EndFunc Same as downloadable file: ParseCmdLine.au3
-
This UDF helps with parsing complex command lines, of the sort you find in Unix command line tools. The approach I have chosen makes a couple assumptions (for instance, boolean switches can't be combined); in exchange the function that does the actual parsing is small and relatively tidy... and it allows for all sorts of command line parameters. For details of how to use ParseCmdLine() see this example: #include <ParseCmdLine.au3> AutoItSetOption("MustDeclareVars",1) AutoItSetOption("ExpandVarStrings",1) ; $args has 5 entries for 5 switches: -nodebug -w -d... -u... -t... ; each entry has 4 parts separated by a | (last part is optional): "type|switch|var|default" ; "type" is either b for a boolean or s for a string switch ; "switch" is what the user has to type on the command line ; "var" is the AU3 variable (w/o the $) which will hold the result (needs not be declared) ; "default" is the default initialiser for "var" ; "default" is optional: if it's mssing a boolean (ie "type" b) comes back false, a string (s) empty ; ; CAUTION: all "switch" strings should be unambiguous; however, a longer "switch" before ; a shorter "switch" in $args should work (ie first "nodebug" and later "n"). The order on ; the command line is irrelevant in any case: -nodebug will never be interpreted as -n"odebug" ; as long as -nodebug is defined before -n ; Global $args[5]=[ _ ; Watch out: the initialisers for -d and -t require 'AutoItSetOption("ExpandVarStrings",1)')! "b|nodebug|DebugMode|True", _ ; boolean -nodebug: $DebugMode is True if switch is not specified "b|w|Write|False", _ ; boolean -w: $Write is False if switch is not specified "s|d|Dir|@SCRIPTDIR@\", _ ; string -d...: $Dir is Scriptdir if switch is not specified "s|u|User|St. Jacques", _ ; string -u...: $User is St. Jacques if switch is not specified "s|t|Time|@HOUR@:@MIN@:@SEC@" _ ; string -t...: $Time is current time if switch is not specified ] ; Another example: ; the "switch" part can also include a separator or other special characters: ; the following means -nodebug -w -dir=... -name=... -n ; using -nodebug, -name and -n in one command line is probably not a good idea (see comment above) ;Global $args[5]=["b|nodebug|DebugMode|True","b|w|Write","s|dir=|Dir|c:\test","s|name=|Name|Holy Cow!","b|n|NoFiles"] ; as $CmdLine[] is a read-only array (strange idea, that... and something ; the AU3 documentation should mention in passing), parsing has to be done with a copy Global $cl=$CmdLine If _ParseCmdLine($cl,$args)=0 Then If @Error=2 Then ConsoleWrite("error in $args[] while parsing: "&$args[@extended]&@CRLF) ElseIf @Error=3 Then ConsoleWrite("error in $cl[] while parsing: "&$cl[@extended]&@CRLF) EndIf Exit EndIf ; at this point $cl[] holds only unprocessed switches and non-switch command line args ; so let's see the results after parsing: WriteVar("$Dir") WriteVar("$User") WriteVar("$Time") If $DebugMode Then ConsoleWrite("Debugging on"&@CRLF) If $Write Then ConsoleWrite("Writing enabled"&@CRLF) ;If $NoFiles Then ConsoleWrite("No files"&@CRLF) ConsoleWrite($cl[0]&" command line argument(s) after parsing:"&@CRLF) For $i=1 To $cl[0] WriteVar("$cl["&$i&"]") Next Func WriteVar($v) ConsoleWrite($v&"=!>"&Execute($v)&"<!"&@CRLF) EndFunc Download the UDF: ParseCmdLine.au3 One nice feature I had working but removed is the capability to call AutoIt3 code for the initialiser. This is (or rather it would be) a powerful feature, but Execute() is not a powerful function. In fact, Execute(), as it is right now, looks more like a pretty bad joke. IMHO, it should be either removed from the language or it should be fully supported. Anyway, give the stuff a whirl.
-
This looks interesting... something I will have to do one of these days. Though one treeview would probably be more elegant for what I have in mind. Re speed: did you look into the UDF for traversing a directory tree I wrote a couple of weeks ago? This is a little slower than the Run/Comspec/dir /s method but OTOH this will deliver the files and directories ready for "immediate consumption" and is much more flexible as well. Even if this should turn out to be not perfect for your purpose the code might give you some ideas. Or perhaps I should try to graft your code onto mine
-
RegExp - has anyone seen this library before?
thomasl replied to sohfeyr's topic in AutoIt Technical Discussion
Try this: $s="Why not test this for yourself?" $p="((?P<named>.\s.).+(?P=named))" $b=StringRegExp($s,$p,3) for $i=0 to Ubound($B)-1 ConsoleWrite("!"&$b[$i]&"!"&@CRLF); next However, named groups don't seem, as yet, to work in StringRegExpReplace(). If you send Jon a bottle of champagne maybe he'll consider implementing that. -
RegExp - has anyone seen this library before?
thomasl replied to sohfeyr's topic in AutoIt Technical Discussion
YES! This is a very, very useful tool to learn REs and to understand how they work (or why they don't). I use it myself when I am sure I am right but the blasted expression doesn't do what it's supposed to do. It is, however, not based on PCRE, so there are some subtle differences (mostly of a pretty esoteric nature). -
With the 3.2.1.7 beta finally out (which has the PCRE regular expression engine included) problems of the kind gcriaco described can be easily solved with an expression like that: (?i)(?!^unins.*\.exe$)^.*\.exe$ This finds all .exe files but not uninst*.exe I have also included another flag in the code that inverses the search pattern. This is probably more useful for the simpler wildcard matches: $files=_DirWalk("c:\","*.exe",5) returns all files that are not .exes.
-
RegExp - has anyone seen this library before?
thomasl replied to sohfeyr's topic in AutoIt Technical Discussion
The | meant, means and will for the foreseeable future mean OR in REs. The effect you see is another case of RTFM. You don't need a | in your context. In fact, it's plain wrong here and the very reason why you got this empty string back: you asked to match EITHER a number OR something else. During the first matching attempt the number is duly matched and returned in the first group. The second group remains empty because it is never initialised: "A set of alternatives matches a string if ANY of the alternatives match [...]. It tries the alternatives left to right AND STOPS ON THE FIRST MATCH THAT ALLOWS SUCCESSFUL COMPLETION OF THE ENTIRE REGULAR Expression." (Quoted from Programming Perl, my emphasis.) Think short-circuit evaluation in a classical if: if f1() or f2() then ... If f1() returns true f2() is never called. That's exactly what happened here. REs are like a programming language: you get back what you asked for and not what you believe you asked. -
Oops. Changed DirWalk.au3 so that it now #includes <file.au3>. For the time being just #include this before you #include DirWalk.au3. Off the top of my head try this one: "^(??!unins.*\.exe).)*$" It works here. The problem is that this expression only works with the new regex engine which is still in beta. So that won't help you for the time being. But I will prepare another version of DirWalk that'll allow you to invert the result of the pattern matching... this should make this sort of thing easier. Stay tuned.
-
I am currently translating some of my local Perl utilities to "pure" AU3: the goal is to learn the language and to see whether AU3 can replace some of the more complex Perl stuff I wrote over the years. (I especially would like to integrate my utilities with the AU3 GUI..() functions: Perl can be rather dry in that respect -- think command line.) Anyway, among the first things I moved to AutoIt3 was a smallish UDF that helps with finding files and directories. These functions work w/o calling any external programs, they only use AU3 APIs. They either do a single directory or will traverse a whole tree; they support both conventional wildcards (i.e. "w*.do?") and regular expressions ("^(?i)w.+\.(exe|dll|bat)$" will find w*.exe, w*.dll and w*.bat [1]). There is not much in the way of finding filenames these functions can't do (if you do find something, tell me ). The price for that flexibility is that the advanced mode can be a little tricky to master. The simple mode is easy: call the main function with a a path, pattern, the right flags... and it will return an array with the matching file and directory names: $files=_DirWalk("c:\","*",1) ; reads all of c:\ The advanced mode is where the real fun starts: for that you have to define one or two callback functions that will be called for every file and directory that is found. The callbacks can do whatever you want, including terminating the search. (In fact, the easy mode is implemented in terms of these two callbacks, so there is a working example of this in the library itself.) One significant advantage of the callback approach is that this allows complete integration into the GUI message loop. See the included GUI example if that's all Greek to you. But even for-non GUI uses the callback approach has advantages as it gives full control over the whole process. Well, the proof is in the eating, as they say, so here's the GUI example code: #include <GUIConstants.au3> #include <DirWalk.au3> AutoItSetOption("MustDeclareVars",1) Global $ed_Path,$ed_Pattern,$chk_Recurse,$chk_RE,$btn_Go,$btn_Stop,$btn_Copy,$ed_Out,$msg,$flags GUICreate("DirWalkGUI",1024,768,197,115,$WS_SIZEBOX+$WS_SYSMENU) GUICtrlCreateLabel("Path:",8,8,34,20) $ed_Path=GUICtrlCreateInput("c:\",64,8,593,24) GUICtrlCreateLabel("Pattern:",8,46,49,20) $ed_Pattern=GUICtrlCreateInput("*",64,46,593,24) $chk_Recurse=GUICtrlCreateCheckbox("Recurse",672,8,81,25) $chk_RE=GUICtrlCreateCheckbox("Regular expression",672,48,153,25) $btn_Go=GUICtrlCreateButton("Search!",872,8,81,24,0) $btn_Stop=GUICtrlCreateButton("Stop!",872,46,81,24,0) $btn_Copy=GUICtrlCreateButton("Copy to clipboard",8,96,153,25,0) $ed_Out=GUICtrlCreateEdit("",8,128,1001,609) GUICtrlSetState($btn_Stop,$GUI_DISABLE) GUICtrlSetState($ed_Path,$GUI_FOCUS) GUICtrlSetLimit($ed_Out,1024*1024) GUISetState(@SW_SHOW) Func FileCB($name,$isdir,$level) Local $msg $msg=GUIGetMsg() If $msg=$GUI_EVENT_CLOSE Then Exit If $msg=$btn_Stop Then Return $DW_BREAK_ALL If $isdir Then ; do nothing Else GUICtrlSetData($ed_Out,$name&@CRLF,1) Endif Return $DW_CONTINUE EndFunc While 1 $msg=GUIGetMsg() Select Case $msg=$GUI_EVENT_CLOSE Exit Case $msg=$btn_Go GUICtrlSetData($ed_Out,"") GUICtrlSetState($btn_Go,$GUI_DISABLE) GUICtrlSetState($btn_Copy,$GUI_DISABLE) GUICtrlSetState($btn_Stop,$GUI_ENABLE) $flags=0 If GUICtrlRead($chk_Recurse)=$GUI_CHECKED Then $flags=1 If GUICtrlRead($chk_RE)=$GUI_CHECKED Then $flags+=2 _DirWalk(GUICtrlRead($ed_Path),GUICtrlRead($ed_Pattern),$flags,"FileCB") GUICtrlSetState($btn_Stop,$GUI_DISABLE) GUICtrlSetState($btn_Copy,$GUI_ENABLE) GUICtrlSetState($btn_Go,$GUI_ENABLE) Case $msg=$btn_Copy ClipPut(GUICtrlRead($ed_Out)) EndSelect WEnd oÝ÷ Ø(ì!jÛ"^Ê'²^½êìÚºÚ"µÍÚ[ÛYH Ð^K]LÉÝÂÚ[ÛYH Ñ[K]LÉÝÂÚ[ÛYH ÑØ[Ë]LÉÝÂ]]Ò]Ù]Ü[Û ][ÝÓ]ÝXÛUÉ][ÝËJB]]Ò]Ù]Ü[Û ][ÝÑ^[Ý[ÜÉ][ÝËJBÛØ[ ÌÍÜK ÌÍÜ ÌÍÜÂY ÌÍÐÛY[VÌOLÈ[RY ÌÍÐÛY[VÌWOI][ÝË]É][ÝÈ[BIÌÍÜOIÌÍÐÛY[VÌBBWÑÜ] ÌÍÜK ÌÍÜBQ[ÙBBIÌÍÜOIÌÍÐÛY[VÌWBBIÌÍÜIÌÍÐÛY[VÌBQ[YIÌÍÜÏIÌÍÐÛY[VÌ×B[ÙBIÌÍÜOI][ÝØÎÌLÉ][ÝÈÈÛÚÈ[ÎÌLÂIÌÍÜI][ÝÝÚJ][ÝÈÈÛÚÈÜÚJIÌÍÜÏLHÈXÝÙHÝÛHÚÛHYB[YÛÛÛÛUÜ]J ][ÝÐÛÛXÝ[È[Ë][ÝÊBÛØ[ ÌÍÙWÑØ[Ê ÌÍÜK ÌÍÜ ÌÍÜÊBY ÌÍÙÌH[PÛÛÛÛUÜ]J ][ÝÐÔ^H[ÙNÔ ][ÝÊBQÜ ÌÍÚOLHÈ ÌÍÙÌBBPÛÛÛÛUÜ]J ][ÝÈ ][ÝÉ[ÉÌÍÙÉÌÍÚWI[ÐÔBS^[ÙBPÛÛÛÛUÜ]J ][ÝÐÔÝ[ÈÝ[Ô ][ÝÊB[YÛÛÛÛUÜ]JÔBÈÈÙÈHØ[XÚÂ[È[PÐ ÌÍÛ ÌÍÙ ÌÍÛ BRY ÌÍÙ[BPÛÛÛÛUÜ]J ][ÝÈ ][ÝÊBQ[ÙBBPÛÛÛÛUÜ]J ][ÝÈ[N ][ÝÊBQ[YPÛÛÛÛUÜ]J ][ÝÉÌÍÛÌÍÈÉÌÍÛ ÌÍ×PÔ ][ÝÊBT] ÌÍÑ×ÐÓÓSQB[[ÂÛÛÛÛUÜ]J ][ÝÐØ[XÚÈ[ÙNÔ ][ÝÊBÑØ[Ê ÌÍÜK ÌÍÜ ÌÍÜË ][ÝÑ[PÐ][ÝÊBoÝ÷ ض¬µ»ey«-*ÖjY»{ay@ÅÛö®¶sb6æ6ÇVFRÖöæ6P¢6æ6ÇVFRfÇC´fÆRæS2fwC°£²6æ6ÇVFRfÇC´FV'Vuw&FRæS2fwC° ¤6öç7Bb33c´Euô4ôåDåTSÓ¤6öç7Bb33c´Euô%$T³Ó¤6öç7Bb33c´Euô%$TµôÄÃÓ £²ÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒУ²fWrçFW&æÂgVæ7Föç0 ¤6öç7Bb33cµôEuô%$ô$õTäCÓc@¤vÆö&Âb33c¶uöGuGFW&âÂb33c¶uöGtfÆW5³ÒÂb33c¶uöGu&V7W'6RÂb33c¶uöGtçfW'BÂb33c¶uöGtfÆT4"Âb33c¶uöGtF$4"Âb33c¶uöGtÆWfVÀ £²çFW&æÂFVfVÇB6ÆÆ&6²f÷"fÆW0£²b33c¶æÖR2FRgVÆÂfÆVæÖRæRâæ6ÇVFærF£²b33c¶6F"2fÇC²fwC³bb33c¶æÖR2F&V7F÷'£²b33c¶ÆWfVÂ2FRF&V7F÷'ÆWfVÂvööBb6ÆÆVB&V7W'6fVÇ£°£²&WGW&ç2b33c´Euô4ôåDåTRFò6öçFçVRFRvư£²÷"b33c´Euô%$T²Fò7F÷7W'&VçBF&V7F÷'vư£²÷"b33c´Euô%$TµôÄÂFò7F÷vƶær6öׯWFVǤgVæ2ôçFW&æÄfÆT4"b33c¶æÖRÂb33c¶6F"Âb33c¶ÆWfV b33c¶uöGtfÆW5³Ò³Ó bb33c¶uöGtfÆW5³ÓÕT&÷VæBb33c¶uöGtfÆW2FVâ&TFÒb33c¶uöGtfÆW5µT&÷VæBb33c¶uöGtfÆW2²b33cµôEuô%$ô$õTäEÐ b33c¶uöGtfÆW5²b33c¶uöGtfÆW5³ÕÓÒb33c¶æÖP bb33c¶6F"FVà ´FV'Vuw&FRgV÷C´F#¢W2VgV÷C²Âb33c¶æÖRÂb33c¶ÆWfV VÇ6P ´FV'Vuw&FRgV÷C´fÆS¢W2VgV÷C²Âb33c¶æÖRÂb33c¶ÆWfV VæD` &WGW&âb33c´Euô4ôåDåTP¤VæDgVæ0 £²çFW&æÂFVfVÇB6ÆÆ&6²f÷"F&V7F÷&W0£²b33c¶æÖR2FRgVÆÂF&V7F÷'æÖRæRâæ6ÇVFærF£²b33c¶ÆWfVÂ2FRF&V7F÷'ÆWfVÀ£°£²&WGW&âfÇVW26VRôçFW&æÄfÆT4"¤gVæ2ôçFW&æÄF$4"b33c¶æÖRÂb33c¶ÆWfV¢bb33c¶ÆWfVÂfwC³FVà ´FV'Vuw&FRgV÷C´VçG'¢W2VgV÷C²Âb33c¶æÖRÂb33c¶ÆWfV VÇ6P ´FV'Vuw&FRgV÷C´WB¢W2VgV÷C²Âb33c¶æÖRÂb33c¶ÆWfV VæD` &WGW&âb33c´Euô4ôåDåTP¤VæDgVæ0 £²çFW&æÂv÷&¶÷'6RÂ6â6ÆÂG6VÆb&V7W'6fVǤgVæ2ôF%vƵ÷&V7W'6Rb33c·F Æö6Âb33c¶ÓÂb33c¶g2Âb33c¶gVÆÂÂb33c¶fÆW5²b33cµôEuô%$ô$õTäEÒÂb33c¶2Âb33c¶@ b7G&æu&vBb33c·FÃfÇC²fwC²gV÷C²b3#²gV÷C²FVâb33c·Ff׳ÒgV÷C²b3#²gV÷C° b33c¶g3ÔfÆTfæDf'7DfÆRb33c·FfײgV÷C²¢gV÷C² bb33c¶g3ÒÓFVâ&WGW&à vÆR b33c¶³Ó bb33c¶ÕT&÷VæBb33c¶fÆW2FVâ&TFÒb33c¶fÆW5µT&÷VæBb33c¶fÆW2²b33cµôEuô%$ô$õTäEÐ b33c¶fÆW5²b33c¶ÓÔfÆTfæDæWDfÆRb33c¶g2 bW'&÷"FVâWDÆö÷ tVæ@ fÆT6Æ÷6Rb33c¶g2 b33c¶fÆW5³ÓÒb33c¶Ó f÷"b33c¶ÓFòb33c¶fÆW5³Ð b33c¶gVÆÃÒb33c·Ffײb33c¶fÆW5²b33c¶Ð b33c¶CÕô4F&V7F÷'b33c¶gVÆÂ bb&E÷"b33c¶uöGtçfW'BÅ7G&æu&VtWb33c¶fÆW5²b33c¶ÒÂb33c¶uöGuGFW&âFVà b33c¶3Ô6ÆÂb33c¶uöGtfÆT4"Âb33c¶gVÆÂÂb33c¶BÂb33c¶uöGtÆWfV bb33c¶2fÇC²fwC²b33c´Euô4ôåDåTRFVâWDÆö÷ VæD` bb33c¶BæBb33c¶uöGu&V7W'6RFVà b33c¶uöGtÆWfVÂ³Ó b33c¶3Òb33c´Euô4ôåDåTP b6ÆÂb33c¶uöGtF$4"Âb33c¶gVÆÂÂb33c¶uöGtÆWfVÂÓFVâb33c¶3ÕôF%vƵ÷&V7W'6Rb33c¶gVÆÂ 6ÆÂb33c¶uöGtF$4"Âb33c¶gVÆÂÂÒb33c¶uöGtÆWfV b33c¶uöGtÆWfVÂÓÓ bb33c¶3Òb33c´Euô%$TµôÄÂFVâWDÆö÷ VæD` æW@ &WGW&âb33c¶0¤VæDgVæ0 £²ÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒУ²WFW&æÂgVæ7Föç0 £²ô4F&V7F÷'b33c·2£²VÇW"gVæ7Föã¢&WGW&ç2fÇVRfwC³bb33c·22F&V7F÷'¤gVæ2ô4F&V7F÷'b33c·2 &WGW&â7G&ætå7G"fÆTvWDGG&"b33c·2ÂgV÷C´BgV÷C²¤VæDgVæ0 £²ôF%vƲb33c·FÒgV÷C²âb3#²gV÷C²Âb33c·GFW&ãÒgV÷C²¢gV÷C²Âb33c¶fÆw3ÓÂb33c¶fÆV6#ÒgV÷CµôçFW&æÄfÆT4"gV÷C²Âb33c¶F&6#ÒgV÷CµôçFW&æÄF$4"gV÷C²£²vÆ·2F&V7F÷'æB6â&WGW&âFRfÆW2öF&V7F÷&W2f÷Væ@£°£²b33c·F2FRFFòÆöö²ã²F26â&R3¢b3#²÷"C¢b3#µvæF÷w0£²b33c·GFW&â2FRGFW&âFòÆöö²f÷#²F26âVFW"&Râõ2×GRvÆF6&@£²æRâ¢æFóò÷"&VwVÆ"W&W76öâ6VRb33c¶fÆw2£°£²FRfÆw2&R&BÖ6öFVBfÇVW2æB6â&Rg&VVÇ6öÖ&æVC £²bb33c¶fÆw3ÓFVâb33c·F2vƶVBF÷vâ&V7W'6fVÇ£²bb33c¶fÆw3Ó"FVâb33c·GFW&â2&VwVÆ"W&W76öâFöâb33·Bf÷&vWBââââb33c²`£²÷RvçBFRGFW&âæ6÷&VB£²bb33c¶fÆw3ÓBFVâFR&W7VÇBöbFRGFW&âÖF62çfW'FVBæRâr¢æWP£²vÆÂ&WGW&âÆÂfÆW2¦W6WB¢r¢æWRfÆW2£°£²bb33c¶fÆV6"2FVfæVBB×W7B&RFRæÖRöbgVæ7FöâFB2W6VB2£²6ÆÆ&6²f÷"ÆÂfÆW2æBF&V7F÷&W2f÷VæC²6VRôçFW&æÄfÆT4"£²bb33c¶F&6"2FVfæVBB×W7B&RFRæÖRöbgVæ7FöâFB2W6VB2£²6ÆÆ&6²&Vf÷&RögFW"&V7W'6ærF÷vâ÷WF&V7F÷'²6VRôçFW&æÄF$4"£²bVFW"6ÆÆ&6²2æ÷BFVfæVBFRçFW&æÂFVfVÇB2W6VC¢ôçFW&æÄfÆT4"£²7F÷&W2ÆÂfÆW2æBF&V7F÷&W2ââ'&v62&WGW&æVB'F2gVæ7FöࣲôçFW&æÄF$4"FöW2æ÷Færà¤gVæ2ôF%vƲb33c·FÒgV÷C²âb3#²gV÷C²Âb33c·GFW&ãÒgV÷C²¢gV÷C²Âb33c¶fÆw3ÓÂb33c¶fÆV6#ÒgV÷CµôçFW&æÄfÆT4"gV÷C²Âb33c¶F&6#ÒgV÷CµôçFW&æÄF$4"gV÷C² b33c¶uöGu&V7W'6SÔ&DæBb33c¶fÆw2à b33c¶uöGtçfW'CÓ b&DæBb33c¶fÆw2ÃBFVâb33c¶uöGtçfW'CÓ²ÖÆöö²6ÆÇ'WBFöâb33·B6ævP b33c¶uöGtfÆW5³ÓÓ b33c¶uöGtfÆT4#Òb33c¶fÆV6 b33c¶uöGtF$4#Òb33c¶F&6 b&DæBb33c¶fÆw2Ã"FVà b33c¶uöGuGFW&ãÒb33c·GFW&à VÇ6P b33c·GFW&ãÕ7G&æu&WÆ6Rb33c·GFW&âÂgV÷C²âgV÷C²ÂgV÷C²b3#²âgV÷C² b33c·GFW&ãÕ7G&æu&WÆ6Rb33c·GFW&âÂgV÷C³ògV÷C²ÂgV÷C²âgV÷C² b33c¶uöGuGFW&ãÕ7G&æu&WÆ6Rb33c·GFW&âÂgV÷C²¢gV÷C²ÂgV÷C²â¢gV÷C² b33c¶uöGuGFW&ãÒgV÷CµâögV÷C²fײb33c¶uöGuGFW&âfײgV÷C²b33c²gV÷C° VæD` b33c¶uöGtÆWfVÃÓ ôF%vƵ÷&V7W'6Rb33c·F &WGW&âb33c¶uöGtfÆW0¤VæDgVæ0 £²ôF%7ÆB'&Vbb33c·GFW&âÄ'&Vbb33c·F£²VÇW"gVæ7Föã¢æFÆ6W2vÆF6&BGFW&â÷F6öÖ&æFöâ7V6F@£²B6âW6VBf÷"ôF%vƲ¢Wöâ6ÆÆærÂb33c·GFW&âöÆG2F&V7F÷'£²æBö÷"GFW&ââF227ÆBÂ6òFRWöâ&WGW&âb33c·GFW&â2§W7BFP£²GFW&â'BæBb33c·FâââvVÆÂÂFRF¢Òââ÷FW"v÷&G2Âb33c·F0£²÷fW'w&GFVâ'F26öFR⣲F2gVæ7FöâFöW2äõB7W÷'B&VwVÆ"W&W76öç2ÂöæÇvÆF6&G2b333°¤gVæ2ôF%7ÆB'&Vbb33c·GFW&âÄ'&Vbb33c·F Æö6Âb33c¶CÂb33c¶C"Âb33c¶C0 bb33c·GFW&âfÇC²fwC²gV÷C²¢gV÷C²FVà bô4F&V7F÷'b33c·GFW&âFVà b33c·FÒb33c·GFW&à b33c·GFW&ãÒgV÷C²¢gV÷C° VÇ6P õF7ÆBb33c·GFW&âÂb33c·FÂb33c¶CÂb33c¶C"Âb33c¶C2 ´FV'Vuw&FRgV÷C´gFW"7ÆC¢b333²W2b333²W2b333²W2b333²W2b333²gV÷C²Âb33c·FÂb33c¶CÂb33c¶C"Âb33c¶C2 b33c·Ff׳Òb33c¶C b33c·GFW&ãÒb33c¶C"fײb33c¶C0 bb33c·GFW&ãÒgV÷C²gV÷C²FVâb33c·GFW&ãÒgV÷C²¢gV÷C° VæD` VÇ6P b33c·FÒgV÷C²âb3#²gV÷C° VæD`¤VæDgVæ0 All three files in one zip: DirWalk.zip Please give it a whirl and tell me what you think. (AU3-wise I am a noob so any hints how to do things more AU3-like are appreciated.) --- [1] For those who are not (yet ) into regular expressions, this beast says the following: ^ match from the beginning of the string (?i) ignore case w match w .+ match any character, one or more times (that's the * in wildcards) \. match a literal dot ( match either exe exe |dll or dll |bat or com ) $ match end of string That's all there is to it. EDIT: Changed DirWalk.au3 so that it now includes <File.au3> on its own. Thanks gcriaco. EDIT 2: Included a new flag for inverting the result of the pattern match and uploaded new version
-
RegExp - has anyone seen this library before?
thomasl replied to sohfeyr's topic in AutoIt Technical Discussion
I have not followed this subthread in any detail (I slept ), but perhaps it helps to bear in mind couple of points: PCRE is trying very hard to be Perl compatible. But there are some unavoidable differences (see the doc); what's more, Perl itself is a moving target There is no final instance that is to decide which RE engine is right and which is wrong. Many problems (more than most people realise) are solvable by throwing a RE or two at them. But not all: some people still try to write patterns that match valid HTML. REs are just a tool and like any tool it pays to know when and how to use it (and perhaps more importantly, when not to use it). -
RegExp - has anyone seen this library before?
thomasl replied to sohfeyr's topic in AutoIt Technical Discussion
Before I posted that I checked the pattern with three different RE engines, all agree So I think something is brewing. However, I think I'll call it a day, lads. -
RegExp - has anyone seen this library before?
thomasl replied to sohfeyr's topic in AutoIt Technical Discussion
Not true, but it certainly helps. Don't want to be a spoilsport, Jon, but there's still the problem of some matches terminating early when they stumble across a \n (see my EDIT "OTOH, StringRegExp("test"&@CRLF&"test","(.*?)",3) simply stops matching after the LF" above.) -
RegExp - has anyone seen this library before?
thomasl replied to sohfeyr's topic in AutoIt Technical Discussion
Here's another thing to chew over. $s="test"&@CRLF&"test" ConsoleWrite($s&@CRLF) $s=StringRegExpReplace($s,".","_") ConsoleWrite($s&@CRLF) This replaces everything with the exception of the LF (ie it also replaces the CR): test test !!!!! !!!! Now this whole CR/LF handling is a thorny problem anyway. Perl REs have an option that switches between \n (which Perl assumes to be "\n" under *x and "\r\n\" under Win32) being treated like a string terminator (ie not matched by a .) or as just another character. Your code seems to work under the assumption that \n is a terminator, not a normal character, which is fine for most matches and replaces (though at some point there should be an option to switch this off). But I am not sure about the semantics in terms of coding for AU3: if LF is not replaced, perhaps CR shouldn't either. EDIT: Here's more. StringRegExp("test"&@CRLF&"test",".",3) works as expected: nine matches (2*4 for the test's and 1 for the CR). OTOH, StringRegExp("test"&@CRLF&"test","(.*?)",3) simply stops matching after the LF. -
RegExp - has anyone seen this library before?
thomasl replied to sohfeyr's topic in AutoIt Technical Discussion
Thx. (The previous build did work after all..., after I got me flaming paths sorted ) Now all is well. Well, almost... StringRegExp("F1oF2oF3o","(F.o)*?",3) should give seven matches. AU3 gives only three, omitting the four empty matches (the other example -- "(.*? )" -- works): -- AU3 :F1o AU3 :F2o AU3 :F3o Perl: Perl:F1o Perl: Perl:F2o Perl: Perl:F3o Perl: -- I will continue to throw REs at it. EDIT: Mode 4 hangs with StringRegExp("test","(.*?)",4)