String/Data Manipulation

Hi Team,

Need help regarding string manipulation,

I want to read each line that starts with ‘Task’ in the below string.
further,1. I have to pick-the initial no,i.e between ‘task:’ and ‘description’.
2.I have to capture the code between 'description: and ‘-’,
3.extract text between ‘-’ and Price.

What I did is first used used regex pattern '“(?<=” + labelBefore + “)(.*?)(?=” + labelAfter + “)” and removed whatever is above ‘Task’ and before ‘Thank you’
then splitted data on the basis of string.split(“Task”) and used for each to get ‘item’-each row.
Now how to extract the values from item(one row).

below is the input string:-
Dear abc,

This is regarding reference number 826123, the following info have been identified:

Task: 18212402 Description: 121 - gas leakage ,not completed Price: $98.50
Task: 32321720 Description: Rejected Price: $0.00
Task: 34017280 Description: 131 - This will be repaired once spare available Price: $38.50
Task: 66017240 Description: 139 - sent for repair Price: $16.50

Thank you,

xyz.
Email: s@a.com

Hi @prateekjain1992
use this first
(?<=Task:)(.?)(?=Description:)
(?<=Description:)(.
?)(?=-)
(?<=not completed Price:)(.*?)(?=$)

Th@nks
@shwin S

Hi @AshwinS2,

If i use ’ (?<=Task:)(. *?)(?=Description:) 'and store the output using string(0).value ,it gives me first record only…there could be single or multiple lines with Task.

Therefore I thought of splitting on the basis of Task line.

Hi @prateekjain1992

Use string manipulations by doing splIt within Excel like substring or index

Thanks
Ashwin.S

The input string is in email body.

Hi @prateekjain1992

Try to split based on string variable

Thanks
Ashwin.S

Hi
Welcome back to uipath community
Regex would be very helpful out here
The expression for the first one would be

(?<=Task:).*(?=Description:)

And for the second one would be

(?<=Description:).*(?=-)

And for the final would be

(?=-).*(?<=Price)

Hope this would help you
And while getting string(0) use Trim along with that like this String(0).value.ToString.Trim so that blank spaces in front and back of the string will be deleted

Kindly try this and let know for any queries or clarification
Cheers @prateekjain1992

HI @Palaniyappan,

There could be single or multiple rows starting with Task,how am i gonna check those.
I thought of splitting first on the basis of Task,and inside for each use this regex.
But giving error in for each.

These expressions would take any number rows after Task
But the described delimiters like Task, Description, -, Price must be there along the strings
If they are present then we would get the value in between them for sure

May I know what was the error you were getting in for each loop
Because I tested with regex101.com with those expressions and it was working fine, giving all the outputs correctly

Cheers @prateekjain1992

@Palaniyappan,the regex is working fine,my question is…if i
use String(0).value.ToString.Trim it will give me result of only first value with (0),how to make this dynamic,there could be one ,two or n no of result.

Fine got it
Let’s go step by step
—once after using this expression in a Matches activity
(?<=Task:).*(?=Description:)
Get the output with a variable of type from that activity
—then use a for each activity where pass that variable as input and change the type argument as System.Text.RegularExpressions.Regex.Match
—then inside the loop use a writeline activity like this
item.ToString.Trim
This will type all the values of each match one by one

Similarly repeat the same for other matches with a for each loop followed by that

Cheers @prateekjain1992

Hi,
I would suggest to use this regex

Task:(?<TaskNo>.*)Description:(?<DescFull>((?(.+?\-.+?)(?<DescCode>(.+))(?:(\-\w*)))(?<DescBody>.+?)))Price: \$(?<Price>\d+\.\d{2})

tick modifier Multiline
you should then loop foreach founded matches and
access to the requred isubstringg by names
( smthing like .Groups.Item(“Name”).value )
Substrings Names are:
TaskNo - for task number
DescriptionCode for number after Description
DescriptionBody for text after code
Price is for price

just noticed that website eats some symbols in regex . hope I would able correctly expose them :slight_smile:

hi @AshwinS2

While using this regex online it is giving result (?<=Price:)(.*?)(?=$) but in uipath it is not giving result,maybe because of ‘$’.

any other alternative ,i need to extract the price.