Regex - Ignore piece of text

Discuss RoboTask here

Regex - Ignore piece of text

Postby Rukbunker » Tue Jun 29, 2021 6:05 pm

Hello Oleg,

We execute a command line tool which exports possible errors to a text file, errors.txt. The content of these file can be "19 55 A4 F6 88", or just "88". The thing is, I should program Robotask in a way it DOESN'T take action when 88 occurs, but it SHOULD respond when any other error occurs. The errors can occur in different orders, so "55 88 7F" is also possible.

If the file is empty (= 0 kB) it shouldn't do anything, that part is already covered.

I've played around with RegEx, like \b(?!88)\b\S+

What is the best approach in this? A RegEx loop or match in combination with if / else's?

If the errorfile is empty = No action (DONE)
If errorfile ONLY contains "88" = No action
If error has errors, including 88 = Ignore 88, proceed with others
Rukbunker
 
Posts: 145
Joined: Mon Feb 22, 2016 4:06 pm
Location: Netherlands

Re: Regex - Ignore piece of text

Postby Oleg » Tue Jun 29, 2021 6:44 pm

look at my task
It extracts all error codes from string in the loop and skips the error 88
So you get your algorithm:
if empty -> nothing
if 88 only -> nothing
if many errors -> process all errors except 88
Code: Select all
;*****************************
;* RoboTask Task file
;* Do not edit in text editor!
;*****************************
 
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|1075658632
Comment=STRINGLIST
ContinueOnError=INTEGER|0
DisableOnError=INTEGER|0
DoNotStopWhenShutdown=INTEGER|0
ExternalName=STRING|"Task1137"
Hide=INTEGER|0
ID=INTEGER|-1406772994
LogOnAsUser=INTEGER|1
Name=STRING|"Extract error codes"
OnErrorTaskID=INTEGER|-1
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|3
UnicodeFormat=INTEGER|1
WriteGeneralLog=INTEGER|0

[Actions]
Action1=FOLDER
Action10=FOLDER
Action11=FOLDER
Action12=FOLDER
Action13=FOLDER
Action14=FOLDER
Action2=FOLDER
Action3=FOLDER
Action4=FOLDER
Action5=FOLDER
Action6=FOLDER
Action7=FOLDER
Action8=FOLDER
Action9=FOLDER

[Actions\Action1]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""str"" with value ""55 88 7F"""
Params=FOLDER

[Actions\Action1\Params]
expand=STRING|"0"
varname=STRING|"str"
varvalue=STRING|"55 88 7F"

[Actions\Action10]
ActionID=STRING|"A_FLOW_IF"
Enabled=INTEGER|-1
Name=STRING|"If Then"
Params=FOLDER

[Actions\Action10\Params]
case=STRING|"0"
connection=STRING|"0"
count=STRING|"1"
operator=STRING|"7"
type=STRING|"0"
value1=STRING|"{txt}"

[Actions\Action11]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show ""No errors to process"""
Params=FOLDER

[Actions\Action11\Params]
icon=STRING|"1"
msg0=STRING|"No errors to process"
msgcount=STRING|"1"
playsound=STRING|"0"
showmessage=STRING|"1"

[Actions\Action12]
ActionID=STRING|"A_FLOW_ELSE"
Enabled=INTEGER|-1
Name=STRING|"Else"

[Actions\Action13]
ActionID=STRING|"A_DIALOG_SHOWTEXT"
Enabled=INTEGER|-1
Name=STRING|"Show Text"
Params=FOLDER

[Actions\Action13\Params]
autoclose=STRING|"0"
fromfile=STRING|"1"
line00000000=STRING|"Errors are:"
line00000001=STRING|"{txt}"
linecount=STRING|"2"
timeout=STRING|"10"

[Actions\Action14]
ActionID=STRING|"A_FLOW_ENDIF"
Enabled=INTEGER|-1
Name=STRING|"End If"

[Actions\Action2]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""txt"" with value """""
Params=FOLDER

[Actions\Action2\Params]
expand=STRING|"0"
varname=STRING|"txt"

[Actions\Action3]
ActionID=STRING|"A_REGEXP_LOOP"
Enabled=INTEGER|-1
Name=STRING|"RegExp Loop"
Params=FOLDER

[Actions\Action3\Params]
anchored=STRING|"0"
case=STRING|"0"
extended=STRING|"0"
line00000000=STRING|"{str}"
linecount=STRING|"1"
multiline=STRING|"0"
noautocapture=STRING|"0"
pattern=STRING|"([A-F0-9]{2})"
savelengths=STRING|"0"
saveoffsets=STRING|"0"
singleline=STRING|"0"
ungreedy=STRING|"0"
useexternal=STRING|"0"
variable=STRING|"err"

[Actions\Action4]
ActionID=STRING|"A_FLOW_IF"
Enabled=INTEGER|-1
Name=STRING|"If Then // err=88 - skipped"
Params=FOLDER

[Actions\Action4\Params]
case=STRING|"0"
connection=STRING|"0"
count=STRING|"1"
operator=STRING|"0"
type=STRING|"0"
value1=STRING|"{err(0)}"
value2=STRING|"88"

[Actions\Action5]
ActionID=STRING|"A_LOOP_CONTINUE"
Enabled=INTEGER|-1
Name=STRING|"Continue"

[Actions\Action6]
ActionID=STRING|"A_FLOW_ELSE"
Enabled=INTEGER|-1
Name=STRING|"Else"

[Actions\Action7]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""txt"" with value ""{txt}{err(0)}{EOL}"""
Params=FOLDER

[Actions\Action7\Params]
expand=STRING|"1"
varname=STRING|"txt"
varvalue=STRING|"{txt}{err(0)}{EOL}"

[Actions\Action8]
ActionID=STRING|"A_FLOW_ENDIF"
Enabled=INTEGER|-1
Name=STRING|"End If"

[Actions\Action9]
ActionID=STRING|"A_LOOP_END"
Enabled=INTEGER|-1
Name=STRING|"End Loop"
Oleg Yershov
Oleg
Site Admin
 
Posts: 2668
Joined: Thu Jan 01, 1970 1:00 am

Re: Regex - Ignore piece of text

Postby Rukbunker » Tue Jun 29, 2021 8:08 pm

And again, you've pushed me into the right direction. My way of thinking was too different (wrong?) from your approach. Never thought of this setup!
Many thanks!
Rukbunker
 
Posts: 145
Joined: Mon Feb 22, 2016 4:06 pm
Location: Netherlands


Return to General Discussion

Who is online

Users browsing this forum: Google [Bot] and 9 guests