Save found subexpressions

Discuss RoboTask here

Save found subexpressions

Postby crisp212 » Thu Mar 15, 2018 7:50 pm

Good afternoon Oleg,

Two questions:

1)Dont understand the "first expression" and "last expression" from the "save parameters" in the "save found expressions" in "RegExp Match" does. What does it do one or another?

2)What is the best way to reset a variable value in a loop?

The problem is: I have a task, that you helped me to do, that runs every 1sec (cyclic) and checks emails in my account (IMAP mail LOOP) When it checks and finds the pattern "Alert in xxx/xxx" (regExp Match), it saves "xxxx/xxxx" into a subexpression (subexpr(1)) and sends me an email of the subexpression (send email). Example: Received email of "Alert in Madrid/Spain" and sends me email with subject "Madrid/Spain". Everything runs great. The thing is is that sometimes, once every 20 emails, it starts a loop that its always me sending me "Madrid/Spain" to my email instead of for example "London/England" or "Moscu/Russia" from a received email. Very rare times but it does start a loop.

Could be because I have selected "Last expression" instead of "First expression"?
Maybe should I put a "break" somewhere so when it starts the loop again, it resets harder the variable value in the subexpression?

Regards and enjoying a lot your soft :) Thnx.


Crisp212
crisp212
 
Posts: 21
Joined: Mon Dec 04, 2017 7:12 pm

Re: Save found subexpressions

Postby Oleg » Fri Mar 16, 2018 11:39 am

1)Dont understand the "first expression" and "last expression" from the "save parameters" in the "save found expressions" in "RegExp Match" does. What does it do one or another?

It seems you told about RegExp Match action. Correct?
The string which you check can contain many expressions matched your pattern. Also it can be different sub-expressions. The action allows to save 1-st or last subexpression.
It the string can contain only one matched expression use "1-st expression" value. You can use "Last expression" with same result.

If you want enumerate all subexpressions in the string you have to use RegExp Loop

2)What is the best way to reset a variable value in a loop?

Use Set Variable action to set any value you want

About other problems
Send you task to me (oleg (at) robotask.com). It seems you made some mistakes in algorithm.
Oleg Yershov
Oleg
Site Admin
 
Posts: 2351
Joined: Thu Jan 01, 1970 1:00 am

Re: Save found subexpressions

Postby crisp212 » Sat Mar 17, 2018 12:24 am

Done. Thanks Oleg! Regards,
crisp212
 
Posts: 21
Joined: Mon Dec 04, 2017 7:12 pm

Re: Save found subexpressions

Postby Oleg » Wed Mar 21, 2018 12:56 pm

I think that information is useful for other users.
So I publish my examples here.

RegExp match action saves some value into EXPR variable only if expression is matched to your pattern. If it is not matched the action keeps the variable stays unchanged.
Look at my two examples
These examples test the line with RegExp Match action in the loop.
Pay attention that 3 lines are matched but 4-th line is not
Look at this example . The variable EXPR contains the previous value at last iteration
Code: Select all
;*****************************
;* RoboTask Task file
;* Do not edit in text editor!
;*****************************
 
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|0
CatID=INTEGER|1951268510
Comment=STRINGLIST
ContinueOnError=INTEGER|0
DoNotStopWhenShutdown=INTEGER|0
Events=FOLDER
ExternalName=STRING|"Task435"
Hide=INTEGER|0
ID=INTEGER|483472358
LogOnAsUser=INTEGER|1
Name=STRING|"mytest 1"
OnErrorTaskID=INTEGER|-1
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|3
UnicodeFormat=INTEGER|1
WriteGeneralLog=INTEGER|0

[Actions]
Action1=FOLDER
Action2=FOLDER
Action3=FOLDER
Action4=FOLDER

[Actions\Action1]
ActionID=STRING|"A_LOOP_TEXT"
Enabled=INTEGER|-1
Name=STRING|"Text Loop"
Params=FOLDER

[Actions\Action1\Params]
destvar=STRING|"SUBJ"
line0=STRING|"Alert on AUD/JPY"
line1=STRING|"Alert on GPB/CAD"
line2=STRING|"Alert on USD/JPY"
line3=STRING|"Hello world"
linecount=STRING|"4"
sourcetext=STRING|"1"

[Actions\Action2]
ActionID=STRING|"A_REGEXP_MATCH"
Enabled=INTEGER|-1
Name=STRING|"RegExp Match"
Params=FOLDER

[Actions\Action2\Params]
anchored=STRING|"0"
case=STRING|"1"
extended=STRING|"0"
line00000000=STRING|"{subj}"
linecount=STRING|"1"
multiline=STRING|"0"
noautocapture=STRING|"0"
pattern=STRING|"Alert on (.+)$"
savesubexpression=STRING|"1"
singleline=STRING|"0"
subexpressionpos=STRING|"0"
subexpressionvar=STRING|"expr"
ungreedy=STRING|"0"
useexternal=STRING|"0"
variable=STRING|"match"

[Actions\Action3]
ActionID=STRING|"A_ROBOTASK_LOG"
Enabled=INTEGER|-1
Name=STRING|"Log Message"
Params=FOLDER

[Actions\Action3\Params]
message=STRING|"{Match}; {expr}; {Expr(1)}"
type=STRING|"3"

[Actions\Action4]
ActionID=STRING|"A_LOOP_END"
Enabled=INTEGER|-1
Name=STRING|"End Loop"

[Events]
Event1=FOLDER

[Events\Event1]
Enabled=INTEGER|-1
EventID=STRING|"E_GENERAL_CYCLIC"
Params=FOLDER
UniqueID=INTEGER|-1705898956

[Events\Event1\Params]
id=STRING|"KV3ANCUN"
interval=STRING|"1"
notsatrtatactivation=STRING|"0"


In order to avoid this just reset the value of EXPR variable before RegExp Match action (look at next example)
Code: Select all
;*****************************
;* RoboTask Task file
;* Do not edit in text editor!
;*****************************
 
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|0
CatID=INTEGER|1951268510
Comment=STRINGLIST
ContinueOnError=INTEGER|0
DoNotStopWhenShutdown=INTEGER|0
Events=FOLDER
ExternalName=STRING|"Task436"
Hide=INTEGER|0
ID=INTEGER|1251330488
LogOnAsUser=INTEGER|1
Name=STRING|"mytest 2"
OnErrorTaskID=INTEGER|-1
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|3
UnicodeFormat=INTEGER|1
WriteGeneralLog=INTEGER|0

[Actions]
Action1=FOLDER
Action2=FOLDER
Action3=FOLDER
Action4=FOLDER
Action5=FOLDER

[Actions\Action1]
ActionID=STRING|"A_LOOP_TEXT"
Enabled=INTEGER|-1
Name=STRING|"Text Loop"
Params=FOLDER

[Actions\Action1\Params]
destvar=STRING|"SUBJ"
line0=STRING|"Alert on AUD/JPY"
line1=STRING|"Alert on GPB/CAD"
line2=STRING|"Alert on USD/JPY"
line3=STRING|"Hello world"
linecount=STRING|"4"
sourcetext=STRING|"1"

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

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

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

[Actions\Action3\Params]
anchored=STRING|"0"
case=STRING|"1"
extended=STRING|"0"
line00000000=STRING|"{subj}"
linecount=STRING|"1"
multiline=STRING|"0"
noautocapture=STRING|"0"
pattern=STRING|"Alert on (.+)$"
savesubexpression=STRING|"1"
singleline=STRING|"0"
subexpressionpos=STRING|"1"
subexpressionvar=STRING|"expr"
ungreedy=STRING|"0"
useexternal=STRING|"0"
variable=STRING|"match"

[Actions\Action4]
ActionID=STRING|"A_ROBOTASK_LOG"
Enabled=INTEGER|-1
Name=STRING|"Log Message"
Params=FOLDER

[Actions\Action4\Params]
message=STRING|"{Match}; {expr}; {Expr(1)}"
type=STRING|"3"

[Actions\Action5]
ActionID=STRING|"A_LOOP_END"
Enabled=INTEGER|-1
Name=STRING|"End Loop"

[Events]
Event1=FOLDER

[Events\Event1]
Enabled=INTEGER|-1
EventID=STRING|"E_GENERAL_CYCLIC"
Params=FOLDER
UniqueID=INTEGER|-1767274076

[Events\Event1\Params]
id=STRING|"KV3ANCUN"
interval=STRING|"1"
notsatrtatactivation=STRING|"0"


Save the text of the task to a file and use menu Task->Import to import the task into RoboTask.
Oleg Yershov
Oleg
Site Admin
 
Posts: 2351
Joined: Thu Jan 01, 1970 1:00 am


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 11 guests

cron