Regex to extract particular string value from the input String

Hi UiPath Team,

I am facing an issue for Extracting the String.

The string is as follows

  1. Return - RDC 01.01 - CAPA Originator
  2. Return - QDV 01.01 - Deviation/CAPA Initiator (US)
  3. ADD - CCC 70.01 - Core Change Control View Only (Legacy)
    4)ADD - CQA 02.02 - Reg Intel-Assessor
  4. MODIFY - ITC 70.01 - ITCC View Only (Legacy) (US)

The strings I am able to fetch is look like above.

Among this strings I want the Value only after “-” and before “()” only.

Means my output should be look like below

1)RDC 01.01 - CAPA Originator
2) QDV 01.01 - Deviation/CAPA Initiator
3) CCC 70.01 - Core Change Control View Only (Legacy)
4) CQA 02.02 - Reg Intel-Assessor
5) ITC 70.01 - ITCC View Only (Legacy)

This are the possible outputs which we need to Extract from the above Strings

kindly help me on this issue to Match the Regex for all the cases.

Thanks
Sreenivasa

Hello Try using below regex
(?<=\-)(.*?)(?=$|\(.*\))

Hi @srinusoft37

Assuming that they are in separate lines,
here strData had 1. Return - RDC 01.01 - CAPA Originator
You can simply use strdata.Split({“-”},2,StringSplitOptions.None)(1).Trim
which will return
image

Thanks and Happy Automation! :smiley:

1 Like

Thanks for quick reply

This is helping me to extract the value after - and before the (), but in few cases we need to extract the () values also

for the 3rd and 5th line I need the data along with the (Legacy) as well
so the pattren should be like

CCC 70.01 - Core Change Control View Only (Legacy)
ITC 70.01 - ITCC View Only (Legacy)

Thanks
Sreenivasa

What is the logic here to decide whether you want to extract this bracket information or not? Or Is it only when we have legacy word we need to extract?. Can you clarify this information?

We have to remove the string if that contains the (US) in the “()” the remaining should be Extracted.

Thanks
Sreenivasa

As simple one
grafik

We would later trim the match results

Thanks for the quick reply.

Yes agree , but not sure which strings contains the value (US). So its could be better if we can remove the values which is (US) along with the string.

Thanks
Sreenivasa

And with the US rule
grafik

1 Like

Thanks for the solution.

Can we add the some other unwanted values if require, Like we did we remove the (US) like that can we remove some other values as well

Thanks
Sreenivasa

We can add value, but that is exactly the reason I was asking how dynamic it can be. Could you provide more example of string which has different format?

1 Like

Hi PPR,

Here is another example which is causing an issue, Like we remove the (US) we need to remove the (Intl) as well. please see the below string

Add - QA 02.01 - AA Originator QC Associate (Intl)

In this also we need to remove the (Intl)

Could you help me on this. in future like if any new unwanted data added I will edit for multiple strings as well.

Thanks
Sreenivasa

Just create a new topic and let us know all different variations as also suggested by

As suggested by Dilip This 2 are the scenarios I have

  1. remove the (US)
  2. Remove the (Intl)

Thanks
Sreenivasa

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