How to fetch the particular word from the sentence

Hi All,

I have the sentance like
I/p-
Name:
Vaishali
Number:
12235
Expected output is

Get separate name & number in two different output like
Name _ vaishali output 1
Number _ 12235 output 2

Thanks

HI @vaishali

You can try with regex expression

Can you share the exact input structure

Regards
Gokul

HI @vaishali

Use Assign Activity

LHS → Create an variable
RHS → System.Text.RegularExpression.Regex.Match("InputString","(?<=Name:\s)(\S+)").Tostring.Trim

image

System.Text.RegularExpression.Regex.Match("InputString","(?<=Name:\n)(\S.+)").Tostring.Trim

image

Use Assign Activity

LHS → Create an variable
RHS → System.Text.RegularExpression.Regex.Match("InputString","(?<=Number:\s)(\d+)").Tostring.Trim

image

System.Text.RegularExpression.Regex.Match(“InputString”,"(?<=Number:\n)(\d+)").Tostring.Trim`

image

Regards
Gokul

1 Like

Hi @vaishali ,

If the Name and Number values are separated by New Lines, then we can use the below Expression :

For Name :

System.Text.RegularExpression.Regex.Match(yourInputStrVar,"(?<=Name:)\n.*").Tostring.Trim

For Number:

System.Text.RegularExpression.Regex.Match(yourInputStrVar,"(?<=Number:)\n.*").Tostring.Trim

Let us know if it doesn’t work for your case and tell us what was the error or issue faced.

Have a look on this general pattern taking label before : and value after linebreak (also made defensive for \r\n Windows linebreaks)

grafik
Refering to groups:
grafik

Pattern:
(^.*?)(?<=\:)(?:\r?\n)(.*)

Also have a look here:
[CheatSheet] - System.Text.RegularExpressions | RegEx - News / Tutorials - UiPath Community Forum

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