Sign in to follow this  
Followers 0
ileandros

StringRegExp / StringSplit

13 posts in this topic

#1 ·  Posted (edited)

Hello there,

I am a few days now trying to understand this commands. I am reading the help files and examples but still nothing...

I got this command in my code which search in a file for lines

Local $aLines = StringRegExp($sLines, "(?:([^v]+)(?:v+|$))", 3) ; Lines to a zero-based array (blank lines not included).
and then i got a loop to find these lines.

My lines are like this

[22:53:48] "Leandros" Leaving
[22:53:50] "Leandros" Leaving
[22:53:53] "Shertaz" ?
[22:54:01] "Mirtid" any tips my friend?

The first two lines are basicly the same but the only thing changing is the time

[22:53:48] "Leandros" Leaving
[22:53:50] "Leandros" Leaving

there are 2 second difference in these lines and thats why my script wont find them. But they are still the same.

Is it able to make it find these same lines even if they have difference in the time?

Edit: Is it also able to make it avoid some lines starting like this?

[Open Server] .........
Edited by ileandros

I feel nothing.It feels great.

Share this post


Link to post
Share on other sites



I'm not very good at this regular expression stuff, but until someone with more know how on this posts, you can play with this?

This is probably what I'd do, I always just use the simple grab everything expression for stuff like this...

#include <Array.au3>
Local $Test[5] = ['[Open Server] .........','[22:53:48] "Leandros" Leaving','[22:53:50] "Leandros" Leaving','[22:53:53] "Shertaz" ?','[22:54:01] "Mirtid" any tips my friend?']
Local $aLines
For $I = 0 To 4
$aLines = StringRegExp($Test[$I], '[(.*):(.*):(.*)] "(.*)" (.*)', 3) ; Lines to a zero-based array (blank lines not included).
_ArrayDisplay($aLines)
Next

Things that I've done..

Icon Resource Editor: icon resource editor 

AutoIt Piano: a piano

AutoIt Unlocker: unlocks files when you want to delete them

Colorful tooltips: a wrapper for the tool tips UDF

Rouge GoogleBot: a full screen animation

ASciTE text editor: a text editor written in autoit

Warning: Posts by this user are subject to change or may disappear without notice.

Share this post


Link to post
Share on other sites

What kind of text are you looking to capture? It might be easier to help knowing what you want.


Gerard J. Pinzonegpinzone AT yahoo.com

Share this post


Link to post
Share on other sites

What kind of text are you looking to capture? It might be easier to help knowing what you want.

Apparently they're IRC logs, they're all usually the same, consisting of time of entry, user name and things they said.


Things that I've done..

Icon Resource Editor: icon resource editor 

AutoIt Piano: a piano

AutoIt Unlocker: unlocks files when you want to delete them

Colorful tooltips: a wrapper for the tool tips UDF

Rouge GoogleBot: a full screen animation

ASciTE text editor: a text editor written in autoit

Warning: Posts by this user are subject to change or may disappear without notice.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Yes, but what format does he want the text captured? Does he want the array to be "22:54:01", "Mirtid", "any tips my friend?"

the regex for that would be

[([^]]+)] "([^"]+)" (.*)

Or to be a more precise capture:

[([0-9]{2}:[0-9]{2}:[0-9]{2})] "([^"]+)" (.*)

Edited by GPinzone

Gerard J. Pinzonegpinzone AT yahoo.com

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

I am not actually writing a file it is just for the example.

I am taking a text that is writen in a window i have and the text inside it is similar as this one i am posting.

Just making it this way so you can understand.

Edit: I just can seem to understand it...

Edited by ileandros

I feel nothing.It feels great.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Here is a better script to understand it

#include <Array.au3>
#include <File.au3>

Local $sFile =  "[22:53:48] Leandros Leaving"&@CR&"[22:53:48] Leandros Leaving"&@CR&"[22:53:53] Shertaz ?"&@CR&"[22:54:01] Mirtid any tips my friend?"
$sFiles = run("notepad.exe")
Sleep(2000)
Send($sFile)
Sleep(1000)
Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase
Local $sWinTitle = "Notepad" ; "WordPad" ;
If WinExists($sWinTitle) Then
    WinActivate($sWinTitle)
    WinWaitActive($sWinTitle)
    Local $sLines = ControlGetText($sWinTitle, "", "") ; 3rd parameter, "", means Active Control.
    Local $aLines = StringRegExp($sLines, "(?:([^v]+)(?:v+|$))", 3) ; Lines to a zero-based array (blank lines not included).
    ;Local $aLines = StringSplit(StringStripCR($sLines), @LF, 2) ; Lines to a zero-based array (blank lines included).
    If IsArray($aLines) Then
        Local $sRes = ""
        ;_ArrayDisplay($aLines)
        For $i = 0 To UBound($aLines) - 1
            For $j = 0 To UBound($aLines) - 1
                If ($i <> $j) And $aLines[$i] == $aLines[$j] Then ; Check if the "$i"'th element exists any where else in the whole array.
                    $sRes &= StringFormat("Line %3d/ is:  ""%s""n", $i + 1, $aLines[$i])
                    ExitLoop
                EndIf
            Next
        Next
        If $sRes = "" Then
            MsgBox(0, "Lines", "There are no lines.", 2)
        Else
            MsgBox(0, "Lines", $sRes)
        EndIf
    Else
        MsgBox(64, "Attention", $sWinTitle & " has no lines present.", 2)
    EndIf
Else
    MsgBox(64, "Attention", $sWinTitle & " window not running.", 2)
EndIf
Edited by ileandros

I feel nothing.It feels great.

Share this post


Link to post
Share on other sites

With association with , this example will call lines duplicate, when lines have the same text and have a time difference of three (3) minutes or less.

;#include <Array.au3>
;#include <File.au3>
#include <Date.au3>

Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase

Local $sWinTitle = "Notepad" ; "WordPad" ;
Local $sFile = _
        "[22:53:48] Leandros Leaving" & @CRLF & _
        "[22:53:50] Leandros Leaving" & @CRLF & _
        "[22:53:53] Shertaz ?" & @CRLF & _
        "[22:54:01] Mirtid any tips my friend?"
Local $sTemp, $TimeDiff, $Time_i, $Time_j, $TimeDiff
Local $sFiles = Run("notepad.exe")
WinWaitActive($sWinTitle)
;Send($sFile)
ControlSetText($sWinTitle, "", "", $sFile)

If WinExists($sWinTitle) Then
    WinActivate($sWinTitle)
    WinWaitActive($sWinTitle)
    Local $sLines = ControlGetText($sWinTitle, "", "") ; 3rd parameter, "", means Active Control.
    Local $aLines = StringRegExp($sLines, "(?:([^v]+)(?:v+|$))", 3) ; Lines to a zero-based array (blank lines not included).
    ;Local $aLines = StringSplit(StringStripCR($sLines), @LF, 2) ; Lines to a zero-based array (blank lines included).
    If IsArray($aLines) Then
        Local $sRes = ""
        ;_ArrayDisplay($aLines)
        For $i = 0 To UBound($aLines) - 1
            $sTemp = StringRegExpReplace($aLines[$i], "([.*])(.*)", "$2")
            For $j = 0 To UBound($aLines) - 1

                If ($i <> $j) And (StringRegExpReplace($aLines[$j], "([.*])(.*)", "$2") == $sTemp) Then ; Check if the "$i"'th element exists any where else in the whole array.
                    ; --------- Get time difference -------------
                    $Time_i = StringRegExpReplace($aLines[$i], "[(.*)](.*)", "$1")
                    $Time_j = StringRegExpReplace($aLines[$j], "[(.*)](.*)", "$1")
                    $TimeDiff = Abs(_DateDiff("s", "2012/01/01 " & $Time_i, "2012/01/01 " & $Time_j))
                    ;Note If the time difference spans the end of the day, for example, "23:59:59" and "00:00:01", a wrong result, 86398, will occur - not 2 secs.
                    ;ConsoleWrite($Time_i & @LF)
                    ;ConsoleWrite($Time_j & @LF)
                    ;ConsoleWrite($TimeDiff & @LF)
                    ; ---------> End of Get time difference -------------

                    If $TimeDiff <= 180 Then ; 180 = 3 minutes
                        $sRes &= StringFormat("Line %3d/ is:  ""%s""n", $i + 1, $aLines[$i])
                        ExitLoop
                    EndIf
                EndIf
            Next
        Next
        If $sRes = "" Then
            MsgBox(0, "Lines", "There are no lines.", 2)
        Else
            MsgBox(0, "Lines", $sRes)
        EndIf
    Else
        MsgBox(64, "Attention", $sWinTitle & " has no lines present.", 2)
    EndIf
Else
    MsgBox(64, "Attention", $sWinTitle & " window not running.", 2)
EndIf

Share this post


Link to post
Share on other sites

With association with , this example will call lines duplicate, when lines have the same text and have a time difference of three (3) minutes or less.

;#include <Array.au3>
;#include <File.au3>
#include <Date.au3>

Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase

Local $sWinTitle = "Notepad" ; "WordPad" ;
Local $sFile = _
        "[22:53:48] Leandros Leaving" & @CRLF & _
        "[22:53:50] Leandros Leaving" & @CRLF & _
        "[22:53:53] Shertaz ?" & @CRLF & _
        "[22:54:01] Mirtid any tips my friend?"
Local $sTemp, $TimeDiff, $Time_i, $Time_j, $TimeDiff
Local $sFiles = Run("notepad.exe")
WinWaitActive($sWinTitle)
;Send($sFile)
ControlSetText($sWinTitle, "", "", $sFile)

If WinExists($sWinTitle) Then
    WinActivate($sWinTitle)
    WinWaitActive($sWinTitle)
    Local $sLines = ControlGetText($sWinTitle, "", "") ; 3rd parameter, "", means Active Control.
    Local $aLines = StringRegExp($sLines, "(?:([^v]+)(?:v+|$))", 3) ; Lines to a zero-based array (blank lines not included).
    ;Local $aLines = StringSplit(StringStripCR($sLines), @LF, 2) ; Lines to a zero-based array (blank lines included).
    If IsArray($aLines) Then
        Local $sRes = ""
        ;_ArrayDisplay($aLines)
        For $i = 0 To UBound($aLines) - 1
            $sTemp = StringRegExpReplace($aLines[$i], "([.*])(.*)", "$2")
            For $j = 0 To UBound($aLines) - 1

                If ($i <> $j) And (StringRegExpReplace($aLines[$j], "([.*])(.*)", "$2") == $sTemp) Then ; Check if the "$i"'th element exists any where else in the whole array.
                    ; --------- Get time difference -------------
                    $Time_i = StringRegExpReplace($aLines[$i], "[(.*)](.*)", "$1")
                    $Time_j = StringRegExpReplace($aLines[$j], "[(.*)](.*)", "$1")
                    $TimeDiff = Abs(_DateDiff("s", "2012/01/01 " & $Time_i, "2012/01/01 " & $Time_j))
                    ;Note If the time difference spans the end of the day, for example, "23:59:59" and "00:00:01", a wrong result, 86398, will occur - not 2 secs.
                    ;ConsoleWrite($Time_i & @LF)
                    ;ConsoleWrite($Time_j & @LF)
                    ;ConsoleWrite($TimeDiff & @LF)
                    ; ---------> End of Get time difference -------------

                    If $TimeDiff <= 180 Then ; 180 = 3 minutes
                        $sRes &= StringFormat("Line %3d/ is:  ""%s""n", $i + 1, $aLines[$i])
                        ExitLoop
                    EndIf
                EndIf
            Next
        Next
        If $sRes = "" Then
            MsgBox(0, "Lines", "There are no lines.", 2)
        Else
            MsgBox(0, "Lines", $sRes)
        EndIf
    Else
        MsgBox(64, "Attention", $sWinTitle & " has no lines present.", 2)
    EndIf
Else
    MsgBox(64, "Attention", $sWinTitle & " window not running.", 2)
EndIf

Well man i dont have words... I opened this thread because i didnt want to get you in so much trouble. I dont know how to thank you...

And it will take time for me to understand this code ;)


I feel nothing.It feels great.

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

I think i found a bug. I dont know if its ready a bug but something is going wrong here.

Change the Local $sFile to this and try it

Local $sFile = _
        "[02:38:25] <Inser>  hello  " & @CRLF & _
        "[03:00:55] <tsakil> enjoy ] <iVespa>" & @CRLF & _
        "[02:43:25] <Inser>  hello  " & @CRLF & _
        "[03:04:54] <tsakil> ] hello  enjoy ] <iVespa>" & @CRLF & _
        "[22:54:01] <Mirtid> any tips my friend?"

It doesnt find the 1st and the 3rd line because of the time that is more that 180 secs but why it says that the 2ond and 4th lines are duplicated????

Edited by ileandros

I feel nothing.It feels great.

Share this post


Link to post
Share on other sites

#11 ·  Posted

I think i found a bug. I dont know if its ready a bug but something is going wrong here.

Change the Local $sFile to this and try it

Local $sFile = _
        "[02:38:25] <Inser>  hello  " & @CRLF & _
        "[03:00:55] <tsakil> enjoy ] <iVespa>" & @CRLF & _
        "[02:43:25] <Inser>  hello  " & @CRLF & _
        "[03:04:54] <tsakil> ] hello  enjoy ] <iVespa>" & @CRLF & _
        "[22:54:01] <Mirtid> any tips my friend?"

It doesnt find the 1st and the 3rd line because of the time that is more that 180 secs but why it says that the 2ond and 4th lines are duplicated????

You are correct. There is a mistake in the Reg Exp pattern. By default ".*" is greedy, and the question mark makes ".*?" un-greedy. In the RE patterns I had "([.*])". This will capture the first open square bracket and everything (including any close square brackets) up to and including the last close square bracket in the test string because ".*" is greedy.

If I had correctly used "([.*?])", this will capture the first open square bracket and everything up to and including the first close square bracket that is encountered from left to right in the test string.

At the time of writing the RE pattern, I expected there would be only one pair of square brackets per line. This would make the greediness of "([.*])" irrelevant.

To explain the RE pattern, "(?;)[^v]+)(?:v+|$))", in the StringRegExp($sLines, "(?:)[^v]+)(?:v+|$))", 3) function:-

(?:...) This outside encompassing non-capturing group is not necessary. It represents one line.

Inside that non-capturing group is "([^v]+)(?:v+|$)" . This has two groups, a capture group (this is the text we want), and a non-capturing group containing characters we do not want to capture.

([^v]+) will capture all characters that are not a vertical white-space character - a line-feed (@LF) or carriage return (@CR).

(?:v+|$) At the end of each line is one or more vertical white-space characters, "v+" or, "|", the end of the test string, "$"

Notice this example uses string manipulation functions other than StringRegExpReplace.

Because the first 10 characters on each line will be in the format "[nn:nn:nn]" , StringTrimLeft, and StringMid functions can be used.

;#include <Array.au3>
;#include <File.au3>
#include <Date.au3>

Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase

Local $sWinTitle = "Notepad" ; "WordPad" ;
#cs
Local $sFile = _
        "[22:53:48] Leandros Leaving" & @CRLF & _
        "[22:53:50] Leandros Leaving" & @CRLF & _
        "[22:53:53] Shertaz ?" & @CRLF & _
        "[22:54:01] Mirtid any tips my friend?"
                #ce
Local $sFile = _
        "[02:38:25] <Inser>  hello  " & @CRLF & _
        "[03:00:55] <tsakil> enjoy ] <iVespa>" & @CRLF & _
        "[02:43:25] <Inser>  hello  " & @CRLF & _
        "[03:04:54] <tsakil> ] hello  enjoy ] <iVespa>" & @CRLF & _
        "[22:54:01] <Mirtid> any tips my friend?"
Local $sTemp, $TimeDiff, $Time_i, $Time_j, $TimeDiff
Local $sFiles = Run("notepad.exe")
WinWaitActive($sWinTitle)
;Send($sFile)
ControlSetText($sWinTitle, "", "", $sFile)

If WinExists($sWinTitle) Then
    WinActivate($sWinTitle)
    WinWaitActive($sWinTitle)
    Local $sLines = ControlGetText($sWinTitle, "", "") ; 3rd parameter, "", means Active Control.
    Local $aLines = StringRegExp($sLines, "(?:([^v]+)(?:v+|$))", 3) ; Lines to a zero-based array (blank lines not included).
    ;Local $aLines = StringSplit(StringStripCR($sLines), @LF, 2) ; Lines to a zero-based array (blank lines included).
    If IsArray($aLines) Then
        Local $sRes = ""
        ;_ArrayDisplay($aLines)
        For $i = 0 To UBound($aLines) - 1
            ;$sTemp = StringRegExpReplace($aLines[$i], "([.*?])(.*)", "$2") ;<- Corrected to be un-greedy (allows for extra "]")
            $sTemp = StringTrimLeft($aLines[$i], 10)
            For $j = 0 To UBound($aLines) - 1

                ;If ($i <> $j) And (StringRegExpReplace($aLines[$j], "([.*?])(.*)", "$2") == $sTemp) Then ; Check if the "$i"'th element exists any where else in the whole array.
                If ($i <> $j) And (StringTrimLeft($aLines[$j], 10) == $sTemp) Then ; Check if the "$i"'th element exists any where else in the whole array.
                    ; --------- Get time difference -------------
                    ;$Time_i = StringRegExpReplace($aLines[$i], "[(.*?)](.*)", "$1") ;<- Corrected to be un-greedy (allows for extra "]")
                    ;$Time_j = StringRegExpReplace($aLines[$j], "[(.*?)](.*)", "$1") ;<- Corrected to be un-greedy (allows for extra "]")
                    $Time_i = StringMid($aLines[$i], 2, 8)
                    $Time_j = StringMid($aLines[$j], 2, 8)
                    $TimeDiff = Abs(_DateDiff("s", "2012/01/01 " & $Time_i, "2012/01/01 " & $Time_j))
                    ;Note If the time difference spans the end of the day, for example, "23:59:59" and "00:00:01", a wrong result, 86398, will occur - not 2 secs.
                    ConsoleWrite($Time_i & @LF)
                    ConsoleWrite($Time_j & @LF)
                    ConsoleWrite($TimeDiff & @LF)
                    ; ---------> End of Get time difference -------------

                    If $TimeDiff <= 180 Then ; 180 = 3 minutes
                        $sRes &= StringFormat("Line %3d/ is:  ""%s""n", $i + 1, $aLines[$i])
                        ExitLoop
                    EndIf
                EndIf
            Next
        Next
        If $sRes = "" Then
            MsgBox(0, "Lines", "There are no lines.", 2)
        Else
            MsgBox(0, "Lines", $sRes)
        EndIf
    Else
        MsgBox(64, "Attention", $sWinTitle & " has no lines present.", 2)
    EndIf
Else
    MsgBox(64, "Attention", $sWinTitle & " window not running.", 2)
EndIf

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Thank you very much for the answer. It was very helpfull belive me. So ur using $sTemp = StringTrimLeft($aLines[$i], 10) which it allows me to use more " ] " and ur using $Time_i = StringMid($aLines[$i], 2, 8) to catch the date right?? This is an easier way as i see and since the writing style inside stays stable it works like a charme. What i want to do ,which ur replaced it at this last post, is this:

Local $sFile = _
        "[02:38:25] <inser>  hello  " &amp; @CRLF &amp; _
        "[03:00:55] <tsakil> enjoy ] <ivespa>" &amp; @CRLF &amp; _
        "[02:43:25] <inser>  hello  " &amp; @CRLF &amp; _
        "[03:04:54] <tsakil> ] hello  enjoy ] <ivespa>" &amp; @CRLF &amp; _
        "[22:54:01] <mirtid> any tips my friend?"

As you can understand the first part represents the Date i write, the second part represents the Name and the third part represents the "Things" i write.

I would easly use StringMid if the names are all the same but they are not.

Before u were using this $Time_i = StringRegExpReplace($aLines[$i], "[(.*?)](.*)", "$1") which didnt allowed me to use more " ] " as i understand.

To be honest i am reading the StringRegExp function and the help files but i cant understand it very much.

How can i catch the name? How can i catch these "<" ">" so i find the name? I wanna test the name if it exists 3 or more times betwen the duplicated names but i dont know how to catch it.. I triend "(? ;)[^v]+)(?:v+|$))" which had no succes.</mirtid></ivespa></tsakil></inser></ivespa></tsakil></inser>

Edited by ileandros

I feel nothing.It feels great.

Share this post


Link to post
Share on other sites

#13 ·  Posted

.... So ur using $sTemp = StringTrimLeft($aLines[$i], 10) which it allows me to use more " ] "....

No, the StringTrimLeft() function was just an alternative function to use instead of using StringRegExpReplace(). All the commented out command lines in my previously posted script work using an alternate function.

....

Before u were using this $Time_i = StringRegExpReplace($aLines[$i], "\[(.*?)\](.*)", "$1") which didnt allowed me to use more " ] " as i understand.

....

No, before I was using this $Time_i = StringRegExpReplace($aLines[$i], "\[(.*)\](.*)", "$1") which didn't allow the use of more " ] ", because of the missing, all important, question mark.

See AutoIt help file > Under "StringRegExp" function > Scroll down to "Repeating Characters" table > At the bottom of table see "? (after a repeating character)". It is this question mark I have been referring to as making ".*?" un-greedy.

I am not referring to the question mark that is one above that follows a character, set or group.

In fact, the immediate above quote is very wrong because $Time_i = StringRegExpReplace($aLines[$i], "\[(.*?)\](.*)", "$1") allows the use of more " ] ", because the question mark following a repeating character is present.

May clarity replace confusion with regard to regular expressions.

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
Sign in to follow this  
Followers 0

  • Similar Content

    • 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)  
    • VIP
      By VIP
      Need help to make function better  with full infomation
      #include <Array.au3> #include <File.au3> _TEST(@ScriptFullPath) _TEST("A:") _TEST("A:\B.c") _TEST("D:\E\F\") _TEST("G:\H/../J.k/") _TEST("M:\N\k..J.k") _TEST("D:\E\F\..\G\G\I..J.K.M") Func _TEST($sFilePath) Local $sDrive = "", $sFullPathDir = "", $sDirPath = "", $sDirName = "", $sFileName = "", $sFileNameExt = "", $sExtension = "", $sExt = "" Local $aPathSplit = _PathSplitByRef($sFilePath, $sDrive, $sFullPathDir, $sDirPath, $sDirName, $sFileName, $sFileNameExt, $sExtension, $sExt) ConsoleWrite("!Path IN : " & $sFilePath & @CRLF) ; C:\Windows\System32\etc\hosts.exe ConsoleWrite("- Driver : " & $sDrive & @CRLF) ; C: ConsoleWrite("- DirPath : " & $sFullPathDir & @CRLF) ; C:\Windows\System32\etc\etc ConsoleWrite("- DirPath : " & $sDirPath & @CRLF) ; \Windows\System32\etc\ ConsoleWrite("- DirName : " & $sDirName & @CRLF) ; etc ConsoleWrite("- FileName : " & $sFileName & @CRLF) ; hosts ConsoleWrite("- FileNameExt: " & $sFileNameExt & @CRLF) ; hosts.exe ConsoleWrite("- Extension : " & $sExtension & @CRLF) ; .exe ConsoleWrite("- Ext : " & $sExt & @CRLF & @CRLF) ; exe ;~ ConsoleWrite("!Path IN : " & $aPathSplit[0] & @CRLF) ; C:\Windows\System32\etc\hosts.exe ;~ ConsoleWrite("- Driver : " & $aPathSplit[1] & @CRLF) ; C: ;~ ConsoleWrite("- DirPath : " & $aPathSplit[2] & @CRLF) ; C:\Windows\System32\etc\etc ;~ ConsoleWrite("- DirPath : " & $aPathSplit[3] & @CRLF) ; \Windows\System32\etc\ ;~ ConsoleWrite("- DirName : " & $aPathSplit[4] & @CRLF) ; etc ;~ ConsoleWrite("- FileName : " & $aPathSplit[5] & @CRLF) ; hosts ;~ ConsoleWrite("- FileNameExt: " & $aPathSplit[6] & @CRLF) ; hosts.exe ;~ ConsoleWrite("- Extension : " & $aPathSplit[7] & @CRLF) ; .exe ;~ ConsoleWrite("- Ext : " & $aPathSplit[8] & @CRLF) ; exe ;~ _ArrayDisplay($aPathSplit, "_PathSplit of " & $sFilePath) EndFunc ;==>_TEST Func _PathSplitByRef($sFilePath, ByRef $sDrive, ByRef $sFullPathDir, ByRef $sDirPath, ByRef $sDirName, ByRef $sFileName, ByRef $sFileNameExt, ByRef $sExtension, ByRef $sExt) If StringInStr($sFilePath,"..") Then $sFilePath=_PathFull($sFilePath) Local $aPartOfPath=StringRegExp($sFilePath, "^\h*((?:\\\\\?\\)*(\\\\[^\?\/\\]+|[A-Za-z]:)?(.*[\/\\]\h*)?((?:[^\.\/\\]|(?(?=\.[^\/\\]*\.)\.))*)?([^\/\\]*))$", $STR_REGEXPARRAYMATCH) ;~ If @error Then ReDim $aPartOfPath[9] ;~ $aPartOfPath[0] = $sFilePath ;~ EndIf $aPartOfPath[0] = $sFilePath ; C:\Windows\System32\etc\hosts.exe $sDrive = $aPartOfPath[1] ; C: $sFullPathDir = $aPartOfPath[1] & $aPartOfPath[2] ; C:\Windows\System32\etc If StringLeft($aPartOfPath[2], 1) == "/" Then $sDirPath = StringRegExpReplace($aPartOfPath[2], "\h*[\/\\]+\h*", "\/") Else $sDirPath = StringRegExpReplace($aPartOfPath[2], "\h*[\/\\]+\h*", "\\") EndIf $aPartOfPath[2] = $sFullPathDir ; C:\Windows\System32\etc $sDirName=StringReplace($sDirPath,"\","") $sDirName=StringReplace($sDirPath,"/","") $sFileName = $aPartOfPath[3] ; hosts $aPartOfPath[5] = $sFileName ; hosts $sExtension = $aPartOfPath[4] ; .exe $aPartOfPath[7] = $sExtension ; .exe $aPartOfPath[3] = $sDirPath ; \Windows\System32\etc\ $aPartOfPath[4] = $sDirName ; etc $aPartOfPath[6] = $sFileName & $sExtension ; hosts.exe $sFileNameExt = $aPartOfPath[6] ; hosts.exe $sExt = StringReplace($sExtension,".","") ; exe $aPartOfPath[8] = $sExt ; exe Return $aPartOfPath EndFunc ;==>_PathSplitByRef  
    • kneze
      By kneze
      Hi
      i try to read Wlan Profiles from local Computer. First Step Command Prompt: netsh wlan show profiles >> C:\temp\test\wlan.txt.
      Second Step (here's a sample script to find a solution for my problem. Script read each line of wlan.txt and Display Name of Wireless Connection which i have set up in the past.  If i edit wlan.txt to wlan - sample.txt script works. wlan.txt containsline without : so i get error message. How can i read only lines beginning with All User Profile so i can use original file wlan.txt which i crate in the command prompt with: netsh wlan show profiles >> C:\temp\test\wlan.txt ?
      Thanks for any suggestions.
      Kneze
      $Form1 = GUICreate("Form1", 374, 268, 892, 512) $Button1 = GUICtrlCreateButton("button", 145, 35, 75, 25) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 $file = "C:\temp\test\wlan.txt" FileOpen($file, 0) For $i = 1 to _FileCountLines($file) $line = FileReadLine($file, $i) $after = StringSplit($line, ":")[2] MsgBox(262144, "Result", $after, 0) Next FileClose($file) EndSwitch WEnd  
       
      wlan - sample.txt
      wlan.txt
    • blemas
      By blemas
      The McAfee return for AV defs per "C:\Progra~1\Common~1\McAfee\SystemCore\csscan.exe -Versions" is ...
      CommonShell Command Line Scanner Lite (VSCORE.15.5.0.3960)
          Engine version: 5800.7501
          DAT version:    8450.0
          Time required:  15 milliseconds
      I want to isolate the actual DAT version as "8450.0".  There may be an easier way to get the DAT Version via other McAfee or registry methods but essentially I just want to know how to parse a string at a character or @CRLF into two separate strings for further parsing. Example:
      $string = "Name=Microsoft Windows 10 Professional |C:\windows|\Device\Harddisk0\Partition2"
      Parse into $var1 = "Name" & $var2 = "Microsoft Windows 10 Professional |C:\windows|\Device\Harddisk0\Partition2"
      From there I'd like to parse $var2 at "|" into  $var3 = "Microsoft Windows 10 Professional" and $var4 "C:\windows|\Device\Harddisk0\Partition2"