Get 3 different values with regex?

Hey everyone,

I get a mail and mail consists of 3 thing.

London
England
7532424

how can i extract each value to variables. i want to save London to a “city” variables England to “country” the code to “postal_code” variable.

I though and tried to do with regex but couldnt make it work.

Thank you all.

btw mail is sent like above:
"
London
England
7532424

…blahblahblahblah
"

so kinda like the first 3 rows is what needed

Hi @berkaykor,
maybe this regex-pattern works for you: (.)\n(.)\n(.)\n
edit: after the dot . must be an asterisk, the forum doesn’t write it in my answer.
grafik
\n is the pattern for a new line, so you get the 3 lines as full match and each line as a group.
You may specify the patterns for (.
) with some more details, maybe only digits for the third line.
edit: I use regex101.com to test my patterns.

Regards
Moritz

thank you how can i assign the the 3 values to variables?

Hi,
You need a IEnumerable variable. You give your mailtext and the search-pattern to the match activity and get the result in the variable YourIEnumerable. Then you can assign the values to different variables. I attach a xaml.
regextester.xaml (5,5 KB)
Hope it works for you!
Moritz

you can use split method
create a variable of type array of strings ex. infoArray

infoArray.Split({" "},StringSplitOptions.None)

you will get the three lines into array items
infoArray(0)
infoArray(1)
infoArray(2)

Hi,

I think with splitting you will get problems with a city like New York, because you split the name.

Moritz

Hi @berkaykor

Further to @mm1904‘s post please check out my Regex Megapost for new users if you want to learn more :blush:

Regex help tutorial MEGAPOST – Making your first Regex post, Reusable Regex Patterns, Regex Troubleshooting, Sample Workflow and more

Hi @Steven_McKeering,
thanks for your link, I’ve stored it in my bookmarks. It’s a great post about regex!
Happy automation!
Moritz

1 Like

Yes, you are totally true :slight_smile:

Thanks for the feedback :blush:

I tried this one, not working tho the logs are like this:

line_1: London
line_2:
line_3: England

and also split is fine london england is a represntitive there wont be more than 1 word in a line. But im not sure how to use it %100.

any help?

@mm1904

Maybe there are more than one characters for a new line in your mail. Did you try your sample and the pattern in regex101.com?
I’m not so familiar with splitting a string, so I don’t know exactly how to use it.

See the attached file for an example on how to use Split() SplitThreeRows.xaml (7.2 KB)

image

2 Likes

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