Jump to content

Recommended Posts

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

Share this post


Link to post
Share on other sites

Any chance to progress it a little further : ?

$aResults = StringRegExp($sFile, "(?i)(FileI×nstall\s|include\s)(.*|s$)", 3)

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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)

 

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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 by Deye

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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 by Deye

Share this post


Link to post
Share on other sites

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 by Deye

Share this post


Link to post
Share on other sites

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 by Deye

Share this post


Link to post
Share on other sites

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)|(?&macro))(\h*[&](\h+[_]\h*\n)?\h*(?&string)|(?&macro))?)+

 

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 by genius257

Share this post


Link to post
Share on other sites

Thank you @genius257,

you are an excellent guide :thumbsup:
last I tried this is the outcome (will have to do for now  :sweating: 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 by Deye

Share this post


Link to post
Share on other sites

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 by Deye

Share this post


Link to post
Share on other sites

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.

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

  • Similar Content

    • By jmp
      i am trying to get number from string using this code :
      #include <IE.au3> $oIE = _IEAttach ("Edu.corner") Local $aName = "Student name & Code:", $iaName = "0" Local $oTds = _IETagNameGetCollection($oIE, "td") For $oTd In $oTds If $oTd.InnerText = $aName Then $iaName = $oTd.NextElementSibling.InnerText $iGet = StringRegExpReplace($iaName, "\D", "") EndIf Next MsgBox(0, "", $iGet) it was get number like 52503058
      But, I want to get only student code 5250. (Different student have different code, sometime its 3 digits, Sometime 4)

       
    • By BlueBandana
      Is there a way to output the regex matches into a file?
      I have a script to compare two files and check for regex matches.
      I want to output the matching regex of 'testexample.txt' to another file.
      #include <MsgBoxConstants.au3> #include <Array.au3> $Read = FileReadToArray("C:\Users\admin\Documents\testexample.txt") $Dictionary = FileReadToArray("C:\Users\admin\Documents\example.txt") For $p = 0 To UBound($Dictionary) - 1 Step 1 $pattern = $Dictionary[$p] For $i = 0 To UBound($Read) - 1 Step 1 $regex = $Read[$i] If StringRegExp($regex, $pattern, 0) Then MsgBox(0, "ResultsPass", "The string is in the file, highlighted strings: " ) Else MsgBox(0, "ResultsFail", "The string isn't in the file.") EndIf Next Next  
    • By therks
      So I have this pattern: 
      ^(?:(\d+)|(\d+):(\d+)|(\d+):(\d+):(\d+))$ And I'm expecting (depending on input) to get a 1, 2 or 3 index array (or @error for invalid input).
      But instead I get this:
      #include <Debug.au3> Func Test($String) _DebugArrayDisplay(StringRegExp($String, '^(?:(\d+)|(\d+):(\d+)|(\d+):(\d+):(\d+))$', 1)) EndFunc Test('10') ; Results (normal, expected): ; Row 0|10 Test('10:20') ; Results (extra blank index): ; Row 0| ; Row 1|10 ; Row 2|20 Test('10:20:30') ; Results (three blank indices): ; Row 0| ; Row 1| ; Row 2| ; Row 3|10 ; Row 4|20 ; Row 5|30 Is this normal? Should I just code around it, or is there a better way to do what I'm looking for?
      I also tried reversing my regex, but it was even uglier results:
      #include <Debug.au3> Func Test($String) _DebugArrayDisplay(StringRegExp($String, '^(?:(\d+):(\d+):(\d+))|(\d+):(\d+)|(\d+)$', 1)) EndFunc Test('10') ; Results (yuck): ; Row 0| ; Row 1| ; Row 2| ; Row 3| ; Row 4| ; Row 5|10 Test('10:20') ; Results (slightly better): ; Row 0| ; Row 1| ; Row 2| ; Row 3|10 ; Row 4|20 Test('10:20:30') ; Results (nice): ; Row 0|10 ; Row 1|20 ; Row 2|30  
    • By FroVN
      i have a text : <Name>Jonh</Name>.<Age>15</Age>
      how i can get Jonh and 15 in one stringregexp? pls give me example
    • By therks
      I'm looking for a regex genius, cus I'm stumped when it comes to assertions.
      So what I have now, is this regular expression: ([^|=]+)=([^|]+)
      It takes a string (user input) of keys=values separated by pipes (ie: "param=value|param=value") and splits them into an array.
      Example:
      $vParamData = 'example=value|fruit=apple|phrase=Hello world' $aRegEx = StringRegExp($vParamData, '([^|=]+)=([^|]+)', 3) ; Result ; [0] => example ; [1] => value ; [2] => fruit ; [3] => apple ; [4] => phrase ; [5] => Hello world So that's working fine, but I'm wondering if there's also a way I could have this capture escaped pipes instead of splitting by them.
      ie:
      $vParamData = 'pipe test=this \| is a pipe|example=value' $aRegEx = StringRegExp($vParamData, '([^|=]+)=([^|]+)', 3) ; I'm getting this: ; [0] => pipe test ; [1] => this \ ; [2] => example ; [3] => value ; But I'd like a result like this: ; [0] => pipe test ; [1] => this \| is a pipe ; [2] => example ; [3] => value Is there some pattern that would accomplish this, or am I better off parsing it some other way?
×
×
  • Create New...