Extract part of string using REGEX

Hello,

I am trying to extract part of the string. The string is

“[k(pgup)k(pgup)k(pgup)k(pgup)]05/02/2019 Updated Credit limit from 300,000.00 to 300000 via credit scoring model[k(enter)k(enter)]”

I want to extract

“05/02/2019 Updated Credit limit from 300,000.00 to 300000 via credit scoring model”

I have tried many things but the issue is date keeps on changing so there is no fixed starting point. Please advise. Thanks in advance for your reply!

Thanks in advance for your reply
Rishi

Does the later part remain the same? Or there are any frequent changes in the structure of this sentence?

Hi Adit,

There will be no change in the structure. The only thing that will change it date and numbers so for example number might be 200 instead of 300,000.00 mentioned in above example. Both ending and beginning starting are static. Only extracted part will change.

Static part

[k(pgup)k(pgup)k(pgup)k(pgup)]

Changing part

05/02/2019 Updated Credit limit from 300,000.00 to 300000 via credit scoring model

Static part

[k(enter)k(enter)]

Try below.

1.Assign activity:
inputString = “[k(pgup)k(pgup)k(pgup)k(pgup)]05/02/2019 Updated Credit limit from 300,000.00 to 300000 via credit scoring model[k(enter)k(enter)]”
2.Assign activity
inputString = inputString.Substring(“[k(pgup)k(pgup)k(pgup)k(pgup)]”.Length)
3.Assign activity
inputString = inputString.Substring(0,inputstring.Length-“[k(enter)k(enter)]”.Length)
4. At end of this below screenshot I gave xaml file. Enjoy and happy automation!

Below is the flow where you can see the string that is needed to you. It can be done with regex also if needed. “05/02/2019 Updated Credit limit from 300,000.00 to 300000 via credit scoring model”

imagesubstring.xaml (5.6 KB)

1 Like

HI @RISHI4897,

If you want to try with Regular expression , use the below regex

image

Hi @RISHI4897

Find use these it works fine
Asign value as string = “[k(pgup)k(pgup)k(pgup)k(pgup)]05/02/2019 Updated Credit limit from 300,000.00 to 300000 via credit scoring model[k(enter)k(enter)]”

in write line use as below regex
System.Text.RegularExpressions.Regex.Replace(Value,“[(.*?)]”,“”).ToString

Thanks

I did not give solution based on regex however I mentioned about it because it is sometimes difficult to understand and debug. Even if the developer looks his own code, he has to put a lot of effort in understanding.

where as in substring, it is straight forward and readable.

If there are two choices, I chose substring way!

Hi @viswanarahari
agreed.
learning new ways is always helpful, but i go with two approaches as per requirement.
in your case inputString = inputString.Substring(“[k(pgup)k(pgup)k(pgup)k(pgup)]”.Length)
has changed to inputString = inputString.Substring([k(pgup)k(pgup)k(pgup)k(pgup)k(pgup)]".Length) then it might through error

@balu, Nice discussion. Do not want to continue on that :slight_smile:

You can see my xaml and its output. There is no error!!

while pasting my code you missed one double quote ? "

Anyway I gave screenshot and xaml file also. Take a look.

Thanks,
Its not about double quote i have added another k(pgup) to string
Yeah nice discussion :slight_smile:

Thanks Regards

Thanks Adit, Viswa Narahari, Anil and Balu. Both of the solutions work for me. Thanks for helping out!

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