Jump to content

[Solved] Reg Expression Not Working


Recommended Posts

So my current script looks for 3 different string types, but the 3rd is not found ( or so I think... it returns 1, but not the string )

$CONTAINER_LIST_EX will return 1, but not the string like the others do.

(?m)([A-Z]{6}\d{11}) will find any string in the following static format ( SEAXXX01234567890, XXXSEA01234567890 )
(?m)([A-Z]{0}99M\d{18}) will find any string in the follow static format ( 99M899374120011048913 )
(?m)([A-Z]{2}\W{19}) is supposed to find the following static string format ( VP5316212CVG042617027 ) VP followed by 7 numbers, followed by 3 letters, followed by 9 numbers.
 

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=..\ICO\Custom-Icon-Design-Flatastic-11-Search-good.ico
#AutoIt3Wrapper_Outfile=..\Compiled\Receive+.Exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#Include <IE.au3>
#Include <Array.au3>
#include <StringConstants.au3>
TrayTip('Viewpoint Manager', 'Script has started.', 1)
;MsgBox(0, 'Instructions', '1. CTRL+A to select, then CTRL+C to copy all containers to the clipboard.' & @CRLF & '2. Press INSERT (INS) to start.' & @CRLF & '3. Press END to close the script.')

#Region HOTKEY
HotKeySet('{INSERT}', 'INPUT_CONTAINER')
HotKeySet('{END}', 'EXT')
#EndRegion

#Region Variables

#EndRegion

#Region Reference
Global $STATIC_DC = ['ATL', 'RDU', 'MCO', 'MEM' & _
                     '', 'BWI', 'PHX', 'BOS', 'STL' & _
                     '', 'CVG', 'EWR', 'DFW', 'ORD' & _
                     '', 'DEN', 'SLC', 'LAX', 'SFO' & _
                     '', 'SEA']

Global $STATIC_TTDWPX = ['99M899374120011048913']

Global $STATIC_TITLE = [0, 'HASSETT', 'SCF', 'RECEIVING', 'ERROR']
#EndRegion

#Region Functions
Func INPUT_CONTAINER()
    $STATIC_TITLE[0] = 1
    Local $CONTAINER_STRING = StringStripWS(ClipGet(), 8)
    Local $CONTAINER_LIST = StringRegExp($CONTAINER_STRING, "(?m)([A-Z]{6}\d{11})", 3) ; (?m)([A-Z]{6}\d{11}) or (?m)([A-Z]{3}[A-Z]{3}\d{11})
    Local $CONTAINER_LIST_EX = StringRegExp($CONTAINER_STRING, "(?m)([A-Z]{2}\W{19})", 3)
    ConsoleWrite($CONTAINER_LIST_EX & @CRLF)
    _ArrayAdd($CONTAINER_LIST, $CONTAINER_LIST_EX)
    If @error = 1 Then
        ;MsgBox(0, 'DEBUG', 'There are no Inbound/Outbound SEA containers found. Trying 99M')
        $STATIC_TITLE[0] = 2
        Local $CONTAINER_LIST = []
        Local $CONTAINER_LIST = StringRegExp($CONTAINER_STRING, "(?m)([A-Z]{0}99M\d{18})", 3)
        If @error = 1 Then
            ;MsgBox(0, 'DEBUG', 'There are no 99M containers found. Trying 53')
        EndIf
    EndIf
    Local $CONTAINER = UBound($CONTAINER_LIST)
    Local $COUNTER = UBound($CONTAINER_LIST)

Do
    For $i = 0 To UBound($CONTAINER_LIST) - 1
        If UBound($CONTAINER_LIST) > 0 Then
            Send($CONTAINER_LIST[$i])
            Send('{ENTER}')
            $COUNTER = $COUNTER -1
            ToolTip('Script is running. ' & $COUNTER & '/' & $CONTAINER & ' remaining.', 1, 1, $STATIC_TITLE[$STATIC_TITLE[0]])
            Local $IE = _IEAttach('https://*', 'url')
            Local $oFrame = _IEGetObjById($IE, 'mainBody')
            Local $oMainBody = $oFrame.contentWindow
            Local $oMessage = StringMid($oMainBody.document.GetElementbyId("message").innertext, 15, 18)
            ;ConsoleWrite($CONTAINER_LIST[$i] & ' - ' & $oMessage & @CRLF)
            If StringCompare($CONTAINER_LIST[$i], $oMessage, $STR_CASESENSE) = True Then
                ConsoleWrite($CONTAINER_LIST[$i] & ' -' & $oMessage & @CRLF)
                ContinueLoop
            Else
                ConsoleWrite('Message not found.' & @CRLF)
                Sleep(IniRead(@ScriptDir & '\Local Settings.ini', 'Options', 'Default Delay', Default))
            Endif
        EndIf
    Next
Until $COUNTER <= 0

If UBound($CONTAINER_LIST) <> 0 Then
    ToolTip('All containers received.', 1, 1, 'Success!')
ElseIf UBound($CONTAINER_LIST) = 0 Then
    $STATIC_TITLE[0] = 4
    ToolTip('There are no containers in the clipboard.', 1, 1, $STATIC_TITLE[$STATIC_TITLE[0]])
EndIf
EndFunc

Func EXT()
    Exit
EndFunc
#EndRegion

While 1
Sleep(10)
WEnd

 

Edited by FengHuangWuShen
Link to comment
Share on other sites

Using a simpler snippet, it does:

Local $CONTAINER_STRING = 'VP5316212CVG042617027'
Local $CONTAINER_LIST_EX = StringRegExp($CONTAINER_STRING, "(?m)VP\d{7}[A-Z]{3}\d{9}", 3)
ConsoleWrite(@error & ' ' & @extended & @LF)
_ArrayDisplay($CONTAINER_LIST_EX)

Please post a content raising the issue you hit.

Hint: remember that StringRegExp with option 3 returns an array, not a string.

Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Thanks.

The minor issue I have is, since it reads the clipboard data of the container ID's that I selected, if I only copy 1 container ID to the clipboard, the script won't find anything. The result will just raise the error at the end of my script:

'There are no containers in the clipboard'

But that's very minor I guess, since I can copy and paste 1 container myself, I'm not that lazy haha. But maybe you have a fix for it. Another thing too is, somehow the number 1 is being put into the CONTAINER_LIST array, so it puts the number 1 in the field after all containers have been submitted.

 

Link to comment
Share on other sites

Again, Please post a content raising the issue you hit. Meaning post a string (clipboard content) showing the issue.

My code shows that with only one string (1 line) it does work. So my request is: exhibit a clipboard content raising issues.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Ahem, my script or yours?

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

It was my script initially, then I tried your simulation script, and it finds the single container fine. Maybe it's because I'm using StringStripWS?

It's a minor problem. The real thing I need to do next, if you don't mind helping, is inputting these Container ID's directly to the input Obj, and hitting the button.

Box Obj ID: containerId
Button Obj: unloadContainerBtn

The button I think is just ( $oContainerBtn.document.GetElementbyId("unloadContainerBtn").click()
right?

Link to comment
Share on other sites

Solved. I probably have some redundancies in my code, but everything works 100%. Please let me know if there is anything I can change to make it work more efficiently, or fix my poor coding haha. and Thanks for the help

  • Read all container ID's ( SEAXXX. XXXSEA. 99M, VP )
  • Input directly to the containerID Obj
  • Directly click the unloadContainerBtn
  • No mysterious containers in my list
  • No need for delays, since it reads the message Obj now
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=..\ICO\Custom-Icon-Design-Flatastic-11-Search-good.ico
#AutoIt3Wrapper_Outfile=..\Compiled\Receive+.Exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#Include <IE.au3>
#Include <Array.au3>
#include <StringConstants.au3>
TrayTip('Viewpoint Manager', 'Script has started.', 1)
;MsgBox(0, 'Instructions', '1. CTRL+A to select, then CTRL+C to copy all containers to the clipboard.' & @CRLF & '2. Press INSERT (INS) to start.' & @CRLF & '3. Press END to close the script.')

#Region HOTKEY
HotKeySet('{INSERT}', 'INPUT_CONTAINER')
HotKeySet('{END}', 'EXT')
#EndRegion

#Region Variables

#EndRegion

#Region Reference
Global $STATIC_VENDOR = [0, 'JUST IN TIME CARGO', 'ITS LOGISTICS INC', 'HASSETT AIR EXPRESS' & _
                         '', 'TECHNICOLOR', 'WPX COURIER LLC', 'XPO LOGISTICS']

Global $STATIC_TITLE = [0, 'HASSETT', 'SCF', 'RECEIVING', 'ERROR']
Global $STATIC_LENGTH[3] = [0, 18, 21]
Global $VP_FLAG[1] = [0]
Global $99M_FLAG[1] = [0]
#EndRegion

#Region Functions
Func INPUT_CONTAINER()
    $STATIC_TITLE[0] = 1
    $STATIC_LENGTH[0] = 1
    Local $CONTAINER_STRING = StringStripWS(ClipGet(), 8)
    Local $CONTAINER_LIST = StringRegExp($CONTAINER_STRING, "(?m)([A-Z]{6}\d{11})", 3) ; (?m)([A-Z]{6}\d{11}) or (?m)([A-Z]{3}[A-Z]{3}\d{11})
    If @error = 1 Then
        ;MsgBox(0, 'DEBUG', 'There are no Inbound/Outbound SEA containers found. Trying 99M')
        $STATIC_TITLE[0] = 2
        $STATIC_LENGTH[0] = 2
        $99M_FLAG[0] = 1
        Local $CONTAINER_LIST = []
        Local $CONTAINER_LIST = StringRegExp($CONTAINER_STRING, "(?m)([A-Z]{0}99M\d{18})", 3)
        If @error = 1 Then
            ;MsgBox(0, 'DEBUG', 'There are no 99M containers found. Trying 53')
        EndIf
    EndIf
    Local $CONTAINER_LIST_EX = StringRegExp($CONTAINER_STRING, "(?m)VP\d{7}[A-Z]{3}\d{9})", 3)
    If $CONTAINER_LIST_EX > 1 Then
        $VP_FLAG[0] = 1
        ConsoleWrite($CONTAINER_LIST_EX & @CRLF)
        _ArrayAdd($CONTAINER_LIST, $CONTAINER_LIST_EX)
    EndIf
    Local $CONTAINER = UBound($CONTAINER_LIST)
    Local $COUNTER = UBound($CONTAINER_LIST)

Do
    For $i = 0 To UBound($CONTAINER_LIST) - 1
        If UBound($CONTAINER_LIST) > 0 Then
            Local $IE = _IEAttach('https://*', 'url')
            Local $oFrame = _IEGetObjById($IE, 'mainBody')
            Local $oMainBody = $oFrame.contentWindow
            Local $oContainer_Obj = $oMainBody.document.GetElementById('containerId')
            Local $oData = _IEFormElementSetValue($oContainer_Obj, $CONTAINER_LIST[$i])
            Local $oClick = $oMainBody.document.GetElementById('addContainersBtn')
            If IsObj($oClick) Then
                Local $oClick = $oMainBody.document.GetElementById('addContainersBtn').click()
            Else
                Local $oClick = $oMainBody.document.GetElementById('unloadContainerBtn').click()
            EndIf
            $COUNTER = $COUNTER - 1
            ToolTip('Script is running. ' & $COUNTER & '/' & $CONTAINER & ' remaining.', 1, 1, $STATIC_TITLE[$STATIC_TITLE[0]])
            Local $IE = _IEAttach('https://*', 'url')
            Local $oFrame = _IEGetObjById($IE, 'mainBody')
            Local $oMainBody = $oFrame.contentWindow
            Select
                Case $STATIC_LENGTH[0] = 1
                    Local $oMessage = StringMid($oMainBody.document.GetElementbyId("message").innertext, 15, $STATIC_LENGTH[$STATIC_LENGTH[0]])
                    ConsoleWrite($CONTAINER_LIST[$i] & ' - ' & $oMessage & $STATIC_LENGTH[0] & @CRLF)
                    If StringCompare($CONTAINER_LIST[$i], $oMessage, $STR_CASESENSE) = True Then
                        ConsoleWrite($CONTAINER_LIST[$i] & ' -' & $oMessage & @CRLF)
                        ContinueLoop
                    Else
                        ConsoleWrite('Message not found.' & @CRLF)
                        Sleep(IniRead(@ScriptDir & '\Local Settings.ini', 'Options', 'Default Delay', Default))
                    Endif
                Case $STATIC_LENGTH[0] = 2
                    Local $oMessage = StringMid($oMainBody.document.GetElementbyId("message").innertext, 15, $STATIC_LENGTH[$STATIC_LENGTH[0]])
                    ConsoleWrite($CONTAINER_LIST[$i] & ' - ' & $oMessage & $STATIC_LENGTH[0] & @CRLF)
                    If StringCompare($CONTAINER_LIST[$i], $oMessage, $STR_CASESENSE) = True Then
                        ConsoleWrite($CONTAINER_LIST[$i] & ' -' & $oMessage & @CRLF)
                        ContinueLoop
                    Else
                        ConsoleWrite('Message not found.' & @CRLF)
                        Sleep(IniRead(@ScriptDir & '\Local Settings.ini', 'Options', 'Default Delay', Default))
                    Endif
            EndSelect
        EndIf
    Next
Until $COUNTER <= 0

If UBound($CONTAINER_LIST) <> 0 Then
    ToolTip('All containers received.', 1, 1, 'Success!')
    $99M_FLAG[0] = 0
    $VP_FLAG[0] = 0
ElseIf UBound($CONTAINER_LIST) = 0 Then
    $STATIC_TITLE[0] = 4
    ToolTip('There are no containers in the clipboard.', 1, 1, $STATIC_TITLE[$STATIC_TITLE[0]])
EndIf
EndFunc

Func EXT()
    Exit
EndFunc
#EndRegion

While 1
Sleep(10)
WEnd

 

Edited by FengHuangWuShen
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...