Regex get just the first match at row

Discuss RoboTask here

Regex get just the first match at row

Postby manxasp » Fri Feb 15, 2019 7:10 pm

hiho,

I need to collect only the first match of each line

i have this:

0000000A123456789 908jej0e38h83he 29h8e2e92 e928je2je9j2 2232 0987654A154548759 6484e3
0000000N123458745 3nn88he83he9j3 e039je93ej 39ej309je903 3333 0215487A458745587 587422

i want this:
123456789
123458745

I already tried to use

[A|N](/d/d/d/d/d/d/d/d/d/d)
but return:
123456789
154548759
123458745
458745587
manxasp
 
Posts: 2
Joined: Sat Dec 29, 2018 5:03 pm

Re: Regex get just the first match at row

Postby Oleg » Sun Feb 17, 2019 9:13 pm

Look at my example below. It works
Code: Select all
;*****************************
;* RoboTask Task file
;* Do not edit in text editor!
;*****************************
 
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|444033236
Comment=STRINGLIST
ContinueOnError=INTEGER|0
DoNotStopWhenShutdown=INTEGER|0
ExternalName=STRING|"Task250"
Hide=INTEGER|0
ID=INTEGER|1311298238
LogOnAsUser=INTEGER|1
Name=STRING|"Get 1-st occurrence at the line"
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
Action6=FOLDER
Action7=FOLDER
Action8=FOLDER
Action9=FOLDER

[Actions\Action1]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""TXT"" with value ""0000000A123456789 908jej0e38h83he 29h8e2e92 e928je2je9j2 2232 0987654A154548759 6484e3{EOL}0000000N123458745 3nn88he83he9j3 e039je93ej 39ej309je903 3333 0215487..."""
Params=FOLDER

[Actions\Action1\Params]
expand=STRING|"0"
varname=STRING|"TXT"
varvalue=STRING|"0000000A123456789 908jej0e38h83he 29h8e2e92 e928je2je9j2 2232 0987654A154548759 6484e3{EOL}0000000N123458745 3nn88he83he9j3 e039je93ej 39ej309je903 3333 0215487A458745587 587422"

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

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

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

[Actions\Action3\Params]
destvar=STRING|"LINE"
line0=STRING|"{txt}"
linecount=STRING|"1"
sourcetext=STRING|"1"

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

[Actions\Action4\Params]
anchored=STRING|"0"
case=STRING|"0"
extended=STRING|"0"
line00000000=STRING|"{line}"
linecount=STRING|"1"
multiline=STRING|"0"
noautocapture=STRING|"0"
pattern=STRING|"[A|N](\d\d\d\d\d\d\d\d\d)"
savesubexpression=STRING|"1"
singleline=STRING|"1"
subexpressionpos=STRING|"0"
subexpressionvar=STRING|"expr"
ungreedy=STRING|"0"
useexternal=STRING|"0"
variable=STRING|"found"

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

[Actions\Action5\Params]
case=STRING|"0"
connection=STRING|"0"
count=STRING|"1"
operator=STRING|"0"
type=STRING|"3"
value1=STRING|"{found}"

[Actions\Action6]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""RESULT"" with value ""{result}{expr(1)}{EOL}"""
Params=FOLDER

[Actions\Action6\Params]
expand=STRING|"1"
varname=STRING|"RESULT"
varvalue=STRING|"{result}{expr(1)}{EOL}"

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

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

[Actions\Action9]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show ""{result}"""
Params=FOLDER

[Actions\Action9\Params]
icon=STRING|"1"
msg0=STRING|"{result}"
msgcount=STRING|"1"
playsound=STRING|"0"
showmessage=STRING|"1"

Save the text of the task to a file and use menu Task->Import to import the task into RoboTask.

Let me know if you have some questions.
Oleg Yershov
Oleg
Site Admin
 
Posts: 2455
Joined: Thu Jan 01, 1970 1:00 am


Return to General Discussion

Who is online

Users browsing this forum: MSN [Bot] and 10 guests