Split/Trim/Substring Functions

Team,
What can be best way to Split/Trim for below Requirement ?
Note - Consists lakhs of records

Requirement - Extract anything after 2nd ~ and below space. Input is dynamic for every record.
Eg1 Input = 3~4~Internal Ids~ Output = Internal
Eg2 Input = 24~4~AMCF Ids~ Output = AMCF
Eg3 Input = 24~4~AMEX Bill Ids~ Output = AMEX

Thanks in advance

1 Like

I guess below would be more understandable
Eg1 Input = 3~4~Testing Ids~
Output = Testing
Eg2 Input = 24~4~LOGO Ids~
Output = AMCF
Eg3 Input = 24~4~LOGO Text Ids~
Output = LOGO Text

You Can try this

str_input = 3~4~Internal Ids~

System.Text.RegularExpressions.Regex.Match(str_input,"(?<=~)[A-Za-z]+.*(?=Ids)").Value

output :

@prerna.gupta

@prerna.gupta

try this it will work for all scenarios

System.Text.RegularExpressions.Regex.Match(str_input,"(?<=~)[A-Za-z]+.*(?=Ids)").Value

image

Thanks, its working for 1st two examples but fails for the 3rd example ie
Eg3 Input = 24~4~LOGO Text Ids~
Output = LOGO Text

Hi

say u have multiple lines in the input named Strinput

  1. First let’s split the line with SPLIT method

arr_Strinput = Split(Strinput.ToString, Environment.NewLine)

  1. Now use a FOR EACH activity and pass the above array as input and change the type argument as string

  2. Inside the loop use a assign activity to get the split value using assign activity like this

str_output = Split(Split(item.ToString.Trim, β€œ~”)(2).ToString, β€œ Ids”)(0).ToString

Hope this helps

Cheers @prerna.gupta

1 Like

you can try this expression

System.Text.RegularExpressions.Regex.Match(str_input,"(?<=~)[A-Za-z]+.*(?=Ids)").Value

output :

@prerna.gupta

1 Like

Hi,

Can you try the following expression?

System.Text.RegularExpressions.Regex.Match(yourString,"(?<=^[^~]+~[^~]+~).*?(?=Ids~)").Value

Regards,

1 Like

Hi @prerna.gupta

You can use the below regular expressions to extract the required output.

System.Text.RegularExpressions.Regex.Match(yourstringinput.ToString,β€œ((?<=\~\d+\~)[A-Za-z]+[\sA-Za-z]+(?=\s+Ids))”).Value

image

Hope it helps!!

1 Like

There is one more dynamic variance ie, here the difference is in ids and Ids. It should not be case sensitive.

Input = 9~4~LOGO ids~
Output = LOGO

Its working for some samples. There is one more dynamic variance ie, here the difference is in ids and Ids. It should not be case sensitive.

Input = 9~4~LOGO ids~
Output = LOGO

Also any references for getting detailed understanding of Regex as you guys are really good in these
?

Okay @prerna.gupta

You can use the below regex

System.Text.RegularExpressions.Regex.Match(yourstringinput.ToString,β€œ((?<=\~\d+\~)[A-Za-z]+|[A-Z]+[\sA-Za-z]+(?=\s+Ids))”).Value

Hope you understand!!

Hi,

How about the following?

System.Text.RegularExpressions.Regex.Match(yourString,"(?<=^[^~]+~[^~]+~).*?(?=[Ii]ds~)").Value

Regards,

1 Like

Split method can accommodate here if needed

Just change it to upper on all text like this

str_output = Split(Split(item.ToString.Trim, β€œ~”)(2).ToString.ToUpper, β€œ IDS”)(0).ToString

Cheers @prerna.gupta

1 Like

Try this one

System.Text.RegularExpressions.Regex.Match(str_input,β€œ(?<=~)[A-Za-z]+.*(?=[I|i]ds)”).Value

@prerna.gupta

1 Like

@prerna.gupta

This is the shortest one you can use it

System.Text.RegularExpressions.Regex.Match(yourstringinput.ToString,β€œ((?<=\~\d+\~).*(?=\s+Ids|\s+ids))”).Value

image

1 Like

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