Regular expression to fetch age value after [agebands_1]

Hi Guys
Hope you all doing good, Can you please help me to get age value from ms word document. I have below screen shot data in ms word file and I need to fetch value after
“[agebands_1]” and before “-” like 18. How can I get it by using regex.

Hi @Aleem_Khan

You can install Uipath.word.Activities Package. you can use word application scope and read text activity to read the file and get the output as string.

Regards
Gokul

I need Regex because I am using get text activity and store data in string.

Can you share the Expected output @Aleem_Khan

Hi @Aleem_Khan

Try this below expression

User assign activity
LHS - Create an variable
RHS - System.Text.RegularExpressions.Regex.Match(“Input String”.Trim,"(?<=\d])\s+\d+(?=\s-)").ToString

Hope it works

Regards
Gokul

I need value after [agebands_1]” and before “-” like 18

Only you need the value [agebands_1] @Aleem_Khan

yes I need value [agebands_1]” and before “-” like 18
“[agebands_1]” keyword is unique in my string so I need value after this and before -

Try this pattern @Aleem_Khan

(?<=agebands_1])\s+\d+(?=\s-)

Regards
Gokul

I have written in text file its come like below format

image

Can you share it in the Text file with preservative format @Aleem_Khan

Hi @Aleem_Khan

Try this expression

Use assign activity
LHS - Create an variable (TestData)
RHS - System.Text.RegularExpressions.Regex.Match(“Input String”.Trim,"(?<=agebands_1])\s+a\d+(?=\s-)").ToString

Use assign activity
LHS - Create an variable
RHS - System.Text.RegularExpressions.Regex.Match(TestData.Trim,"\d+").ToString

Hope it will resolve your query

Regards
Gokul

Kindly mark the appropriate post as solved, If you query is resolved @Aleem_Khan

So, that it will help others to

Regards
Gokul

1 Like

Hi resolve this problem by using split method

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