Jump to content
Deye

@ Adding conditions

Recommended Posts

Deye

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
Deye

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
JLogan3o13

@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.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
genius257

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)

 

  • Thanks 1

Share this post


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

  • Thanks 1

Share this post


Link to post
Share on other sites
Deye
Posted (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 by Deye

Share this post


Link to post
Share on other sites
genius257

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

Share this post


Link to post
Share on other sites
Deye
Posted (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 by Deye

Share this post


Link to post
Share on other sites
Deye
Posted (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 by Deye

Share this post


Link to post
Share on other sites
genius257
Posted (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)|(?&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
  • Thanks 1

Share this post


Link to post
Share on other sites
Deye
Posted (edited)

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

Share this post


Link to post
Share on other sites
genius257

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

    • therks
      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  
    • FroVN
      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
    • therks
      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?
    • Robinson1
      By Robinson1
      Well the plan is to use the power of regular expressions engine of AutoIT for patching binary data.
      Something like this: StringRegExp( $BinaryData,  "(?s)\x55\x8B.."
       
      <cut> ... Okay straight to question/problem
      ... certain bytes that are in the range from 0x80 to 0xA0 won't match.
      Hmm seem to be a char encoding problem. In detail these are 27 chars: 0x80, 0x82~8C, 0x8E, 0x91~9C, 0x9E,0x9F
      Here's a small code snippet to explore / explain this problem:
      #include "StringConstants.au3" $TestData = BinaryToString("0x7E7F808182") ;Okay $match = StringRegExp( $TestData ,'\x7E' ,$STR_REGEXPARRAYFULLMATCH) ConsoleWrite('@extended = ' & @extended & ' $match = ' & $match & @CRLF) ;Okay $match = StringRegExp( $TestData ,'\x7F' ,$STR_REGEXPARRAYFULLMATCH) ConsoleWrite('@extended = ' & @extended & ' $match = ' & $match & @CRLF) ;Error no match $match = StringRegExp( $TestData ,'\x80' ,$STR_REGEXPARRAYFULLMATCH) ConsoleWrite('@extended = ' & @extended & ' $match = ' & $match & @CRLF) ;Okay $match = StringRegExp( $TestData ,'\x81' ,$STR_REGEXPARRAYFULLMATCH) ConsoleWrite('@extended = ' & @extended & ' $match = ' & $match & @CRLF) ;Error no match $match = StringRegExp( $TestData ,'\x82' ,$STR_REGEXPARRAYFULLMATCH) ConsoleWrite('@extended = ' & @extended & ' $match = ' & $match & @CRLF) ;~ output: ;~ @extended = 2 $match = ;~ @extended = 3 $match = ;~ @extended = 0 $match = 1 ;~ @extended = 5 $match = ;~ @extended = 0 $match = 1 Hmm what to do? Go back and use the 'numberstring monster' implementation or just omit that range of 'unsafe bytes'. What is the root of this problem?
      Any idea how to fix this?
       
      Update: Okay I know a byte is not a character.
      But StringRegExp operates on String and so character level.
      Okay as long as you stay at Ansi encoding and only use /x00 - /X7F in the search pattern using  StringRegExp works well to search for binary data.
      What bytes can be matched that are in the range from /X7F - /xFF is also depending on the code page.
      So this avoid to search for bytes in the range from 0x80-0xa0 only applies to Germany.
      I just change this country setting:

      to Thai and now near all bytes from /X7F - /xFF fails to match.
    • Carm01
      By Carm01
      Hello,
      I have spent the past day fooling with StringRegExp to no avail attempting to get what would be a simple solution to an issue using StringRegExp.
      I will post the code in a sec. The string 'Java x Update y' where x and y are numeric values ONLY if a letter is mixed in anywhere then it should fail. I have been able to successfully deal with the x value so if x = 1234 or a1234 or 1a234 or 1234a would result in a fail if 'a' was in the string. However, when y = 1a234 then I get an output of 1 and when y = 1234a then the output = 1234 when both should fail. I am probably overlooking something simple and in looking through all the material and experimenting I am unable to figure it out and my experience with stringregexp and trying to find examples of this proved difficult. If someone could assist or point me to a thread ? Here is my code ; prob a simple fix. I am also trying to avoid white spaces.
      Thanks in advance
      #include <array.au3> $aArray = StringRegExp('Java 3009 Update 1a21', '(?i)Java (\d+) Update (\d+)', $STR_REGEXPARRAYGLOBALMATCH) If @error Then Exit _ArrayDisplay($aArray)  
×