Extract E-mail address from text

Discuss RoboTask here
Post Reply
sarnusch
Posts: 48
Joined: Thu Apr 28, 2022 9:05 am

Extract E-mail address from text

Post by sarnusch »

Hello,
I am trying to get an email address out of a string with different information but I can not get it to work.
The domain is always the same: "@example.com"
But the string before the domain is always different and also the length differs.
Before the email address is always at least one space.

Is there a smart way to find the full email address in a string?
Oleg
Site Admin
Posts: 3135
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: Extract E-mail address from text

Post by Oleg »

Is there a smart way to find the full email address in a string?
Yes of course. Use regular expressions
Also look at my small example below.
Save the text of the task to a file and use menu Task->Import to import the task into RoboTask.
Also you can simply copy task text and paste it into the task list.

Code: Select all

;*****************************
;* RoboTask Task file
;* Do not edit in text editor!
;*****************************
 
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|799397369
Comment=STRINGLIST
ContinueOnError=INTEGER|0
DisableOnError=INTEGER|0
DoNotStopWhenShutdown=INTEGER|0
ExternalName=STRING|"Task14"
Hide=INTEGER|0
ID=INTEGER|-753970022
LogOnAsUser=INTEGER|1
Name=STRING|"Extract email address from string"
OnErrorTaskID=INTEGER|-1
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
StepPause=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

[Actions\Action1]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""SourceString"" with value ""Example of string with email address. The address is example.address@example.com. Extract it please."""
Params=FOLDER

[Actions\Action1\Params]
_rt_variables_produced=STRING|"SourceString"
expand=STRING|"0"
linecount=STRING|"1"
varname=STRING|"SourceString"
varvalue=STRING|"Example of string with email address. The address is example.address@example.com. Extract it please."

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

[Actions\Action2\Params]
_rt_variables_produced=STRING|"expression,res"
anchored=STRING|"0"
case=STRING|"0"
extended=STRING|"0"
line00000000=STRING|"{SourceString}"
linecount=STRING|"1"
multiline=STRING|"0"
noautocapture=STRING|"0"
pattern=STRING|"([0-9a-zA-Z_\.]+@[0-9a-zA-Z_]+?\.[a-zA-Z]+)"
savesubexpression=STRING|"1"
singleline=STRING|"0"
subexpressionpos=STRING|"0"
subexpressionvar=STRING|"expression"
ungreedy=STRING|"0"
useexternal=STRING|"0"
variable=STRING|"res"

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

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

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

[Actions\Action4\Params]
icon=STRING|"1"
msg0=STRING|"{SourceString}"
msg1=STRING|"******"
msg2=STRING|"Email is: {expression(1)}"
msgcount=STRING|"3"
playsound=STRING|"0"
showmessage=STRING|"1"

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

[Actions\Action6]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show ""The string does not contain email address!"""
Params=FOLDER

[Actions\Action6\Params]
icon=STRING|"3"
msg0=STRING|"The string does not contain email address!"
msgcount=STRING|"1"
playsound=STRING|"0"
showmessage=STRING|"1"

[Actions\Action7]
ActionID=STRING|"A_FLOW_ENDIF"
Enabled=INTEGER|-1
Name=STRING|"End If"
Oleg Yershov
sarnusch
Posts: 48
Joined: Thu Apr 28, 2022 9:05 am

Re: Extract E-mail address from text

Post by sarnusch »

Hi,
that works perfectly.
Thank you very much!
Post Reply