I need to extract specific key pair from long string

I have a requirement to extract 3 different key pairs from the long string and store it in a dictionary variable .

example
if my string is as below
" here are the details of your incident
Description: your issue is related to application . But please cross check ;
and your
Resolution: your application can be restarted to resolve this .Please try ;
and the root cause fix is
Root Fix: please make code level changes ;"

and my result should be
Result enumerable dictionary,
( Description:your issue is related to application . But please cross check ,
Resolution: your application can be restarted to resolve this .Please try ,
Root Fix: please make code level changes )

Please help me in this .
I have seen regex can be used to fetch any one key pair but i want to extract all three key pairs .

2 Likes

Hi @Abhishek_Aithal1
Do one thing

Read text file
and use add to dictionary

and use for each item
Print the item

Thanks
Ashwin S

Hi Ashwin,

Thanks for the repl .
Adding keypair to dictionary is not the problem here .
I need a way to remove those keypairs out of my string .

Hi @Abhishek_Aithal1
Pass the key value pairs to remove from dictionary

Thanks
Ashwin S

Hi
Hope these steps would help you resolve this
If the above string is in a string variable named str_input

Then use a assign activity like this
arr_str = Split(str_input,”;”)
Where arr_str is a variable of type array of string

Now use a FOR EACH activity and pass the above variable as input
Inside the loop use a assign activity like this
dic_string(Split(item.ToString,”:”)(0).Tostring.Trim) = Split(item.ToString,”:”)(1).ToString.Trim

Where dic_string is a variable of type dictionary(of string) with default value as Nee Dictionary(of string,string)

Cheers @Abhishek_Aithal1

hey @Abhishek_Aithal1 how are you using regex to get only one line item

Hi @Palaniyappan
Thanks for the detailed explanation.
Could you please let me know if there is any way to remove extra words that is comming us in the key position .

example in the above string
“here are the details of your incident
Description: your issue is related to application . But please cross check ;” would be one of the item in list of strings and “here are the details of your incident
Description” would be the key of this dictionary variable .
But i need only “Description” as key .

Would this be possible from regex function to check if the key has “description/Resolution/Root fix” any of these three then consider only this as key expression .

1 Like

Its not number format , I think so each number they added in a img Format.

image

yah we can do that
but we need a structure of string for that
will the string contains the terms like Description, Resolution and Root Fix in order
because we can get the string between Description and Resolution a value for Description
similarly string between Resolution and Root Fix as a value for key Resolution

like wise
@Abhishek_Aithal1

@Abhishek_Aithal1

try this regex to get those three line items
further you can split every line by colon “:” to get it in key value pair
u can also use ismatch activity with same expression to check whether those keywords exist or not

Hi @Abhishek_Aithal1;

You can use regex for this as it’s much faster and stable.

If you’re very sure that all three (Description, Resolution, Root Fix) will be present, you can use the following regex to get all the three item in an array.

(?<=:).*?(?=\;)

Else if you need to get specific one, you need to use the following for each

  • (?<=Description:).*?(?=\;) - Description
  • (?<=Resolution:).*?(?=\;) - Resolution
  • (?<=Root Fix:).*?(?=\;) - Root Fix

Hope this help!

Happy Automation :smiley:

hi @Prafull_B

This worked .But one small changes needed .

expression doesnt pics the string in the next line .

ex:
" description: this is first line .
this is second line .
this is thrird ;
and this is some random redundant line "

expected output:
“description: this is first line .
this is second line .
this is thrird ;”

current output:
“description: this is first line .”

Could you please help me in this

@Abhishek_Aithal1 , how you resolved this issue? Any update. I have the exact requirement.

I would be thankful, if you could share your solution?

Thanks,
Shantanu