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
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
First letβs split the line with SPLIT method
arr_Strinput = Split(Strinput.ToString, Environment.NewLine)
Now use a FOR EACH activity and pass the above array as input and change the type argument as string
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
Yoichi
(Yoichi)
September 26, 2023, 7:54am
10
Hi,
Can you try the following expression?
System.Text.RegularExpressions.Regex.Match(yourString,"(?<=^[^~]+~[^~]+~).*?(?=Ids~)").Value
Regards,
1 Like
mkankatala
(Mahesh Kankatala)
September 26, 2023, 7:57am
11
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
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
?
mkankatala
(Mahesh Kankatala)
September 26, 2023, 8:04am
14
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!!
Yoichi
(Yoichi)
September 26, 2023, 8:05am
15
Hi,
How about the following?
System.Text.RegularExpressions.Regex.Match(yourString,"(?<=^[^~]+~[^~]+~).*?(?=[Ii]ds~)").Value
Regards,
1 Like
Palaniyappan
(Palaniyappan P )
September 26, 2023, 8:05am
16
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
mkankatala
(Mahesh Kankatala)
September 26, 2023, 8:10am
18
@prerna.gupta
This is the shortest one you can use it
System.Text.RegularExpressions.Regex.Match(yourstringinput.ToString,β((?<=\~\d+\~).*(?=\s+Ids|\s+ids))β).Value
1 Like
system
(system)
Closed
September 29, 2023, 8:11am
19
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.