First word in the mail message

Hello there.
I need to extract exatly first word (actually number) of Outlook message body. 1
There can be spaces or “enter” symbols before first word and any other text after first word. Extracting should ignore them.
Can anyone help?
Thank you.!

Hi,
You can refer the following code.
saveMail.xaml (7.3 KB)

System.Text.RegularExpressions.Regex.Replace(item.Body ,"\D","") will leave out all the characters and take only the numbers.
Thanks.

1 Like

Thank you for answer but your code takes all numbers, not first.

Hi @ironman

Give this one a go:
https://regex101.com/r/OqPADW/1

(?=\s|\w)\d+

This one will return the first match:
System.Text.RegularExpressions.Regex.Match(item.Body, "(?=\s|\w)\d+").ToString

3 Likes

This code works fine. Have a look at it

saveMail (1).xaml (9.5 KB)

Thank you .

2 Likes

Hello @ironman

Try this
system.Text.RegularExpressions.Regex.Match(item.Body, “^[0-9]”).ToString

2 Likes

Thank you. It works well. Can you help with code that does same but also takes characters and symbols in first word? Message could have that
%D0%A1%D0%BD%D0%B8%D0%BC%D0%BE%D0%BA2
or that format:
%D0%A1%D0%BD%D0%B8%D0%BC%D0%BE%D0%BA3
Code should extract only marked string.

Thanks!

Thank you. It works well. Can you help with code that does same but also takes characters and symbols in first word? Message could have that
%D0%A1%D0%BD%D0%B8%D0%BC%D0%BE%D0%BA3
or that format:
%D0%A1%D0%BD%D0%B8%D0%BC%D0%BE%D0%BA2

Thanks!

This one is a bit more tricky. Could you provide a sample with actual text and also clarify if the first 5 characters from the second example are always the same?
image

Yes, first 5 characters are always same: “ОБ00-”

Okay, check this one :slight_smile:

https://regex101.com/r/OqPADW/2

(?=\s|\w)\d+|\ОБ00-\d+

2 Likes

This code works well. Thank you very much for your time.:clap::clap::clap::pray:

1 Like