How to extract email id from a string without using regex

I am trying to learn string manipulation and want to extract email ids from strings

For example: “Hello there, this is my email address sagarrawl7764@gmail.com, please send me the document”

How do I extract the email without using regex or any predefine functionalities similar to regex?

1 Like

@indiedev91
If you are not using Regex
then fallow these steps.
1- Split string with space value. It will break your string and all the words will go in in string type array.
2-loop over string array.
3- use string. contains over each iteration and check that its contains "@gamail.com, @outlook.com, and so on.

Note: Its work in case of general case, email can be from different domain. Its not reliable than Regex. Regex is perfect

1 Like

Why you don’t need regex expression @indiedev91

Regards
Gokul

Trying to learn string manipulation, trying to make projects as logical as possible without using predetermined methods

I will start using methods after some time

Hi @indiedev91

Have a look on the tutorial for String Manipulation

Hope this will help you

Regards
Gokul

thanks for the answer i wiill try that

and im just learning string manipulation, eventualkly i will use regex in production

1 Like

@indiedev91 Great. You will become master, you are thinking with different way and you have curiosity that’s amazing

1 Like

Regex Expression @indiedev91

System.Text.RegularExpressions.Regex.Match(YourString,"(?<=email\saddress\s)(\S+)(?=,)").Tostring

Regards
Gokul

Hey @indiedev91,

Have a look on this thread.

Thanks,
Sanjit

Thank you , appreciated

1 Like

i dont want to use regex right now

@indiedev91 yes use my suggestion

Hello @indiedev91 ,
Try this method it may help for you

Split(YourString," ")

You ca use the split string and loop it using for each loop , you can split each string.
Within loop , use if condition for isolate the string contains “@” “.”

item.ToString.Contains("@") And item.ToString.Contains(".")

KIndly refer this flow of XAML file.
EmailString_Manipulation.xaml (9.3 KB)

image

1 Like

the regex is only easy way and dynamic also if you go with string manipulation you cant get efficient

[1]+@([\w-]+.)+[\w-]{2,4}$

this following regex you can use for email


  1. \w-. ↩︎

Hi,

FYI, more strict approach:

validMailCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!#$%&’*+-/=?^_`{|}~."
validDomainCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-."

Then check if valid character as address and domain before/after @ character.

Sequence2.xaml (10.8 KB)

Regards,

image

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.