Deye Posted July 10, 2018 Posted July 10, 2018 Hi, I want to add any needed conditions to the StringRegExp command so it can pull out only "File.au3", "WinAPIFiles.au3", "Test.bmp" into the array #include <FileConstants.au3> #include <MsgBoxConstants.au3> #include 'WinAPIFiles.au3' #include "File.au3" ; Script Start - Add your code below here Local $bFileInstall = False ; Change to True and ammend the file paths accordingly. ; This will install the file C:\Test.bmp to the script location. If $bFileInstall Then FileInstall("C:\Test.bmp", @ScriptDir & "\Test.bmp") $sFile = FileRead(@ScriptFullPath) $aResults = StringRegExp($sFile, "(?i)(FileInstall\s*|include\s*)(.*)", 3) _ArrayDisplay($aResults) Thanks In Advance Deye
Deye Posted July 11, 2018 Author Posted July 11, 2018 Any chance to progress it a little further : ? $aResults = StringRegExp($sFile, "(?i)(FileI×nstall\s|include\s)(.*|s$)", 3)
Moderators JLogan3o13 Posted July 11, 2018 Moderators Posted July 11, 2018 @Deye you have been around long enough to know to wait 24 hours before bumping your post. This may be the most important thing in the world to you, but you need to show some patience. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
genius257 Posted July 12, 2018 Posted July 12, 2018 Hi @Deye. (?(DEFINE) (?<string>(["'])((?!\2).)*\2))(#include ((?&string))|FileInstall\(((?&string))) is what I have so far I will test in AutoIt later here's the Github Gist. To show your appreciation My highlighted topics: AutoIt Package Manager, AutoItObject Pure AutoIt, AutoIt extension for Visual Studio Code Github: AutoIt HTTP Server, AutoIt HTML Parser
genius257 Posted July 12, 2018 Posted July 12, 2018 Hi @Deye. here's what i expect are the solution you want? #AutoIt3Wrapper_Res_File_Add=C:\Users\me\Desktop\88x31.jpg #AutoIt3Wrapper_Res_Icon_Add=C:\Users\me\Desktop\logo.ico #include <FileConstants.au3> #include <MsgBoxConstants.au3> #include 'WinAPIFiles.au3' #include "File.au3" ; Script Start - Add your code below here Local $bFileInstall = False ; Change to True and ammend the file paths accordingly. ; This will install the file C:\Test.bmp to the script location. If $bFileInstall Then FileInstall("C:\Test.bmp", @ScriptDir & "\Test.bmp") $sFile = FileRead(@ScriptFullPath) $pattern = '(?(DEFINE) (?<string>(["''''])((?!\2).)*\2))(?:#include ((?&string))|FileInstall\(((?&string))|#AutoIt3Wrapper_Res_[a-zA-Z]+_Add=([^\n]+))' $aResults = StringRegExp($sFile, $pattern, 3) _ArrayDisplay($aResults) Dim $aResult[0] For $i=0 To UBound($aResults)-1 If StringLen($aResults[$i])>0 Then ReDim $aResult[UBound($aResult)+1] $aResult[UBound($aResult)-1] = StringRegExpReplace($aResults[$i], '^(["''''])(.*)\1', "$2") EndIf Next _ArrayDisplay($aResult) Deye 1 To show your appreciation My highlighted topics: AutoIt Package Manager, AutoItObject Pure AutoIt, AutoIt extension for Visual Studio Code Github: AutoIt HTTP Server, AutoIt HTML Parser
genius257 Posted July 20, 2018 Posted July 20, 2018 On 7/13/2018 at 2:53 PM, Deye said: your StringRegExp() doesn't do: #AutoIt3Wrapper_Res_File_Add=C:\Users\me\Desktop\88x31.jpg, RT_ICON .. (?(DEFINE) (?<string>(["''''])((?!\2).)*\2))(?:#include ((?&string))|FileInstall\(((?&string))|#AutoIt3Wrapper_Res_[a-zA-Z]+_Add=\s*([^\n,]+)) a small update in regards to #AutoIt3Wrapper_Res_[a-zA-Z]+_Add= this should omit text after the comma and allow spaces before the equals sign, just in case. Deye 1 To show your appreciation My highlighted topics: AutoIt Package Manager, AutoItObject Pure AutoIt, AutoIt extension for Visual Studio Code Github: AutoIt HTTP Server, AutoIt HTML Parser
Deye Posted July 20, 2018 Author Posted July 20, 2018 (edited) Thanks genius257 That is exactly what I tried that worked .;. now all is left is to include capturing *.dll that are within quotations In could be : _BASS_FX_Startup(@scriptDir & "\dll\bass_fx.dll") or DllOpen('bass_fx.dll') not DllOpen($sBassDLL) that's why within quotations .. Edit: and something set in to ignore lines with "DllCall" Deye Edited July 20, 2018 by Deye
genius257 Posted July 27, 2018 Posted July 27, 2018 Hi @Deye I would say getting strings, that specify dll files, but not within a dllcall would require some post processing. computation of string concatenation, translation of variables and macros, not to mention translating eval's and executes. Also you would need to check if an expression is being extended to multi-line, with the underscore character. A big Regex might be able to collect all the data you need, but i would argue it's the translation of the artifacts above that is the hard part. To show your appreciation My highlighted topics: AutoIt Package Manager, AutoItObject Pure AutoIt, AutoIt extension for Visual Studio Code Github: AutoIt HTTP Server, AutoIt HTML Parser
Deye Posted July 27, 2018 Author Posted July 27, 2018 (edited) Hi genius257, This is what I have used for the dll part : Just for the sake of getting a cleaner output I added in:|(?m)^.*\QDllCall\E.*\R?(*SKIP)(?!) As for the rest of few leftovers if any .. Its just easy to ignore if they aren't pointing to valid existing .. used with: |[a-zA-Z]+["''''].*dll\b| This leaves a quote to the left StringRegExpReplace($aResults[$i], '^(["''''])(.*)\1', "$2") I think this wont remove quotes if absent in either ends or something alike .. btw : Just now, made another update for the au3 (X) Port tool i needed this for Thanks Deye Edited July 27, 2018 by Deye
Deye Posted July 29, 2018 Author Posted July 29, 2018 (edited) Hi @genius257 actually for the dll part that worked:|["''''].*dll\b| My tool is missing this too, was testing out something but forgot to revert .. I will want to update the tool again for that and for a few more changes .. still, what can be a good 1 pattern for only getting: - the in between parenthesis in lines with #pragma compile #pragma compile(Out, myProg.exe) - along with:#AutoIt3Wrapper_Outfile=myProg.exe #AutoIt3Wrapper_Res_Description= #AutoIt3Wrapper_Res_Fileversion= Thanks Deye Edit: never mind, figured out something .. Edited July 30, 2018 by Deye
Deye Posted August 6, 2018 Author Posted August 6, 2018 (edited) The question at hand is somewhat different from The question at the OP To refine: what can be a pattern that will match and extract "filename & extension" with\without\partial paths Between any none legal characters like quotes or like "=\Users\me\Desktop\88x31.jpg," skipping: #include < *.* > Where I can further customize it to skip commented lines and other certain phrases #include <File.au3> #include "WinAPIShPath.au3" #AutoIt3Wrapper_Res_File_Add=C:\Users\me\Desktop\88x31.jpg, RT_ICON .. #AutoIt3Wrapper_Res_Icon_Add=C:\Users\me\Desktop\logo.ico #include <FileConstants.au3> #include <MsgBoxConstants.au3> #include 'WinAPIFiles.au3' #include "File.au3" ; Script Start - Add your code below here Local $bFileInstall = False ; Change to True and ammend the file paths accordingly. ; This will install the file C:\Test.bmp to the script location. If $bFileInstall Then FileInstall("C:\Test.bmp", @ScriptDir & "\Test.bmp") $pattern = '(([''"])((?!\2).)*\2)' Local $sVar = 'Local $aPath[7] = [''\path\file(1).ext'',''c:\path\file.ext'', ''path\file'', ''c:\path\'', ''c:\'', ''file(1).ext'']' & @CRLF Local $aResults = StringRegExp($sVar, $pattern, 3) _ArrayDisplay($aResults) Local $sFileRead = FileRead(@ScriptFullPath) Local $aResults = StringRegExp($sFileRead, $pattern, 3) _ArrayDisplay($aResults) Thanks Edited August 6, 2018 by Deye
genius257 Posted August 10, 2018 Posted August 10, 2018 (edited) Hi @Deye. So I think you need multiple regular expressions. To make expression(s) you work with less complicated, I would suggest you do the following: remove all comments from the string you are processing. Match (almost) all strings with RegEx below. Take each match and translate it into a complete string with the Execute command. filter results, depending if result is a a legal path depending on your current file system (NTFS, FAT32, ...). Add those results to the regex matching #include ..., #AutoIt3Wrapper_Res_File_Add=... (where you've stripped the part of the string that is not part of the file path) Do whatever you want with the result Note that this RegEx does not support string escapes in the AutoIt syntax. (?(DEFINE)(?<string>(["'])((?!\2).)*\2)(?<spacing>[\h]*)(?<macro>[@][A-Za-z]+))(((?&string)|(?¯o))(\h*[&](\h+[_]\h*\n)?\h*(?&string)|(?¯o))?)+ Hope this is of some use to you. Sorry for the response time, I am the process of moving ^^' Edit: Ofc. my solution does not support methods with string definition either, like: $a = "this is a" & Mood(1) & "day" $b = "this is a" & Mood(0) & "day" Func Mood($good) Return $good?'happy':'sad' EndFunc Edited August 10, 2018 by genius257 Deye 1 To show your appreciation My highlighted topics: AutoIt Package Manager, AutoItObject Pure AutoIt, AutoIt extension for Visual Studio Code Github: AutoIt HTTP Server, AutoIt HTML Parser
Deye Posted August 10, 2018 Author Posted August 10, 2018 (edited) Thank you @genius257, you are an excellent guide last I tried this is the outcome (will have to do for now until i get back to what i was wanting to with this before ..) If anyone keen to have a better RegEx practice for this, to demo here, then you are most welcome .. #cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.14.5 Author: myName Script Function: Template AutoIt script. #include "MsgBoxConstants.au3" #include "StringConstants.au3" #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here #AutoIt3Wrapper_Res_File_Add=C:\Users\me\Desktop\88x31.jpg, RT_ICON .. ; #AutoIt3Wrapper_Res_Icon_Add=C:\Users\me\Desktop\logo.ico ; #include <FileConstants.au3> #include <File.au3> #include "WinAPIShPath.au3" #include 'WinAPIFiles.au3' ; ; Script Start - Add your code below here Local $bFileInstall = False ; Change to True and ammend the file paths accordingly. ; This will install the file C:\Test44.bmp to the script location. If $bFileInstall Then FileInstall("C:\Test.bmp", @ScriptDir & "\Test.bmp") $pattern = '(?m)^\s*\Q;\E.*\R?(*SKIP)(?!)|(?m)^\s*#.*\s*\Q<\E.*\R?(*SKIP)(?!)|(?m)^.*\QDllCall\E.*\R?(*SKIP)(?!)|([\w\.(\:\)*\\w]+\w+.\.\w{3})' Local $sVar = 'Local $aPath[7] = [''\path\file(1).ext'',''c:\path\file.ext.ext.ext'', ''path\file'', ''c:\path\'', ''c:\'', ''..\..\..\file(1).ext'']' & @CRLF Local $sFileRead = FileRead(@ScriptFullPath) Local $aResults = StringRegExp($sFileRead, $pattern, 3) _ArrayDisplay($aResults) Deye Edited August 26, 2018 by Deye
Deye Posted August 26, 2018 Author Posted August 26, 2018 (edited) Hi, Lost my patience and energy with this the last time @ finding a good pattern that finally worked, but couldn't jump back to what i was wanting to do with this yet .. Now I want to add one more thing: something that can ignore lines from instance #cs to instance #ce. if anyone willing to help\ add\compact .. with last touches that would be really great example code @ the newly edited above post TIA Deye Edit : came up with '(?m)#cs([\s\S]*?)#ce(*SKIP)(?!)' for now .. Edited August 26, 2018 by Deye
genius257 Posted August 27, 2018 Posted August 27, 2018 Hi @Deye. Please note that Quote The #comments-start and #comments-end directives can be nested. So something like this: (?s)(?(DEFINE)(?<comment>(#comments-start|#cs)((?!#comments-start|#cs|#ce|#comments-end).)*(?&comment)*((?!#comments-start|#cs|#ce|#comments-end).)*(#comments-end|#ce)))(?&comment) To either remove the comments or check if your other matches are within the comments (if you use flag 1 or 2). You could try to wrap this group in a negative lookahead, but I have not tested if that would work. To show your appreciation My highlighted topics: AutoIt Package Manager, AutoItObject Pure AutoIt, AutoIt extension for Visual Studio Code Github: AutoIt HTTP Server, AutoIt HTML Parser
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