Sign in to follow this  
Followers 0
nhardel

StringRegExp Am looking for help

4 posts in this topic

I am asking for the help of the very experienced coders on this forum. Please guide me thru your wisdom to understanding how to write my pattern for my string search.

I am working on a project that deals with SAP. I am aware that a UDF was written for this but unfortuately my company has chosen not to allow the scripting to be actived. So I have to go the long way around with AUTOIT to script my process. At the particulary part of the script I am working on, I am using wingettext to pull the visable text from the window after performing an action. There are several possible messages that SAP could generate and based on those messages tells my script what to do next.

$error = _checkerrors(wingettext($oie,""))
Select
    Case $error = 0
        _SAP_wait($oIE)
        ConsoleWrite("Creating CCR record for material# "&$material & " on line"&$line&@crlf)
        _createCCR()
        _CCR_controls("Supply area","LINE"&$line,1)
        _CCR_controls("Plant",$plant,1) 
        _CCR_controls("Material",$material,1)
    Case $error = 1
        Consolewrite("Control cycle "&$material&" "&$plant&" LINE"&$line&" already exists"&@crlf)
        _CCR_controls("Supply area","LINE"&$line,1)
        _CCR_controls("Plant",$plant,1) 
        _CCR_controls("Material",$material,1)
    Case $error =2
        ConsoleWrite("Error with material "&$material&".  Please try this material again with manual inspection"&@crlf)
        _CCR_controls("Supply area","00000000000000000000000000000000000000000000",1)
        _CCR_controls("Plant","00000000000000000000000000000000000000000000",1) 
        _CCR_controls("Material","00000000000000000000000000000000000000000000",1)
EndSelect
ConsoleWrite(@crlf)
EndFunc

Func _checkerrors($wintext) 
    Local $error_array[5]
    $error_array[0] = .5
    $error_array[1] = StringInStr($wintext,"Control cycle "&$material&" "&$plant&" LINE"&$line&" already exists") 
    $error_array[2] = Stringregexp($wintext,"(Material (.+) does not exist in plant)")  ;NEED HELP HERE
    $error_array[3] = Stringregexp($wintext,"(Supply area (.+) does not exist)")        ;NEED HELP HERE
    $error_array[4] = 0
    return _ArrayMaxIndex($error_array,1,1)
EndFunc

My requirements are as such

  • I need to make sure that the entire pattern matches
  • Where the (.+) is can be a substring of unknown size or characters
  • I only need to know if the string matches or not (True/False)
  • There could be more messages added later so I can't just check for "Material" or "Supply area" as other messages could be generated that have those words. That's why I am trying to find the entire line.

    I am sure I have overlooked something but I just don't see it. Any ideas :)

Share this post


Link to post
Share on other sites



I am asking for the help of the very experienced coders on this forum. Please guide me thru your wisdom to understanding how to write my pattern for my string search.

I am working on a project that deals with SAP. I am aware that a UDF was written for this but unfortuately my company has chosen not to allow the scripting to be actived. So I have to go the long way around with AUTOIT to script my process. At the particulary part of the script I am working on, I am using wingettext to pull the visable text from the window after performing an action. There are several possible messages that SAP could generate and based on those messages tells my script what to do next.

CODE
$error = _checkerrors(wingettext($oie,""))

Select

Case $error = 0

_SAP_wait($oIE)

ConsoleWrite("Creating CCR record for material# "&$material & " on line"&$line&@crlf)

_createCCR()

_CCR_controls("Supply area","LINE"&$line,1)

_CCR_controls("Plant",$plant,1)

_CCR_controls("Material",$material,1)

Case $error = 1

Consolewrite("Control cycle "&$material&" "&$plant&" LINE"&$line&" already exists"&@crlf)

_CCR_controls("Supply area","LINE"&$line,1)

_CCR_controls("Plant",$plant,1)

_CCR_controls("Material",$material,1)

Case $error =2

ConsoleWrite("Error with material "&$material&". Please try this material again with manual inspection"&@crlf)

_CCR_controls("Supply area","00000000000000000000000000000000000000000000",1)

_CCR_controls("Plant","00000000000000000000000000000000000000000000",1)

_CCR_controls("Material","00000000000000000000000000000000000000000000",1)

EndSelect

ConsoleWrite(@crlf)

EndFunc

Func _checkerrors($wintext)

Local $error_array[5]

$error_array[0] = .5

$error_array[1] = StringInStr($wintext,"Control cycle "&$material&" "&$plant&" LINE"&$line&" already exists")

$error_array[2] = Stringregexp($wintext,"(Material (.+) does not exist in plant)") ;NEED HELP HERE

$error_array[3] = Stringregexp($wintext,"(Supply area (.+) does not exist)") ;NEED HELP HERE

$error_array[4] = 0

return _ArrayMaxIndex($error_array,1,1)

EndFunc

My requirements are as such

  • I need to make sure that the entire pattern matches
  • Where the (.+) is can be a substring of unknown size or characters
  • I only need to know if the string matches or not (True/False)
  • There could be more messages added later so I can't just check for "Material" or "Supply area" as other messages could be generated that have those words. That's why I am trying to find the entire line.

    I am sure I have overlooked something but I just don't see it. Any ideas :party:

You just wanted flag = 0 on your StringRegExp():

#include <Array.au3>

Global $error_array[4], $wintext
Global $avTestInputs[4] = ["Material Silly Putty does exist in plant", _
        "Material Silly Putty does not exist in plant", _
        "Supply area 51 does exist!", _
        "Supply area 51 does not exist (as far as YOU know)"]

For $n = 0 To UBound($avTestInputs) - 1
    $wintext = $avTestInputs[$n]
    $error_array[2] = Stringregexp($wintext, "Material .+ does not exist in plant", 0);NEED HELP HERE
    $error_array[3] = Stringregexp($wintext,"Supply area .+ does not exist", 0)     ;NEED HELP HERE
    _ArrayDisplay($error_array, $n & ": $error_array")
Next

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Okay so I went about that wrong. I was under the impression that I needed the "()" group symbols. I didnt think that I could put the ".+" with out some sort of brackets in the pattern portion of the func. Thank alot PSaltyDS

One other question

Lets say I have the possibility of the two following statements

'Material ######## does exist in plant'

'Material ######## does exist'

How would you go about writing the pattern to look for the second statement but not come back with a True on the first statement.

This would also assume that they are two completely new reads of the wingettext read

CODE
#include <Array.au3>

Global $error_array[4], $wintext

Global $avTestInputs[4] = ["Material Silly Putty does exist in plant", _

"Material Silly Putty does exist", _

"Supply area 51 does exist!", _

"Supply area 51 does not exist (as far as YOU know)"]

For $n = 0 To UBound($avTestInputs) - 1

$wintext = $avTestInputs[$n]

$error_array[0] = StringRegExp($wintext, "Supply area .+ does exist",0)

$error_array[1] = StringRegExp($wintext, "Material .+ does exist in plant",0)

$error_array[2] = Stringregexp($wintext, "Material .+ does exist",0) ;Need something at end of pattern to say if anything else exist then stringregexp = false

$error_array[3] = Stringregexp($wintext,"Supply area .+ YOU know",0)

_ArrayDisplay($error_array, $n & ": $error_array")

Next

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Lets say I have the possibility of the two following statements

'Material ######## does exist in plant'

'Material ######## does exist'

How would you go about writing the pattern to look for the second statement but not come back with a True on the first statement.

This would also assume that they are two completely new reads of the wingettext read

CODE
#include <Array.au3>

Global $error_array[4], $wintext

Global $avTestInputs[4] = ["Material Silly Putty does exist in plant", _

"Material Silly Putty does exist", _

"Supply area 51 does exist!", _

"Supply area 51 does not exist (as far as YOU know)"]

For $n = 0 To UBound($avTestInputs) - 1

$wintext = $avTestInputs[$n]

$error_array[0] = StringRegExp($wintext, "Supply area .+ does exist",0)

$error_array[1] = StringRegExp($wintext, "Material .+ does exist in plant",0)

$error_array[2] = Stringregexp($wintext, "Material .+ does exist\z",0) ; this will match with anchor at EOL/EOS

$error_array[3] = Stringregexp($wintext,"Supply area .+ YOU know",0)

_ArrayDisplay($error_array, $n & ": $error_array")

Next

Look again in the help for StringRegExp. \A anchor at SOL (Start Of Line), \b at word boundary, \z at EOL (End Of Line) or EOS (End Of String), \Z at EOL/EOS or final NewLine...

Have fun.

Edit: btw, I find this part of your first post difficult to understand:

...my company has chosen not to allow the scripting to be actived. So I have to go the long way around with AUTOIT to script my process.

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)

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