How to get the required output from given input using regex or trim or anything? Please help

inputVariable = Program : ZABC_PQ_STP_DM ( ZABC_PQ_STP_DM )

required output:
outputVariable = ZABC_PQ_STP_DM

Hi @anjasing

Take a look at these options:
Option 1
Option 2
Option 3

If you want to learn Regex Check out my Regex MegaPost

Can you expand upon the pattern of text. What is consistent?

Cheers

Steve

EDIT: I had the wrong sample Input :sweat_smile:

Alright, logging off for today :joy:

3 Likes

Hi @anjasing

Try this regex expression

System.Text.RegularExpressions.Regex.Match("InputStr","(?<=Program\s:\s)(\S+)").Tostring.Trim

image

Regards
Gokul

1 Like

Hi @anjasing ,

Using String Split :

Split(Split(inputVariable,":")(1),"(")(0).ToString.Trim
1 Like

Hi @anjasing ,

It depends - are you interested in retrieving the text present within the Brackets or the text preceding the brackets?

I’ve included the solution to both →

image

System.Text.RegularExpressions.Regex.Match(inputVariable,"(?<=\:\s)(.*?)(?=\s?\()").Value

image

System.Text.RegularExpressions.Regex.Match(inputVariable,"(?<=\(\s)(.*?)(?=\s?\))").Value

Do let us know if that works.

Kind Regards,
Ashwin A.K

1 Like

Hi All, Thank you so much for your quick replies.

Thank you so much for the links…that are great!

1 Like

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