Use regex?

Hello.
I have value = AAK-20250314-154055-Trik-4_02SAA

I want expect 3 output
1. AAK-20250314-154055-Trik-4
2. 02SAA-Trik-4
3. 02SAA

Value = AAK-20250364-153865-Trik-10_03ADF
expect 3 output
1. AAK-20250364-153865-Trik-10
2. 03ADF-Trik-10
3. 03ADF
Please guide me for solve it by use regex
Thankyou

Hello.
I have value = AAK-20250314-154055-Trik-4-02SAA

I want expect 3 output
1. AAK-20250314-154055-Trik-4
2. 02SAA-Trik-4
3. 02SAA

Value = AAK-20250364-153865-Trik-10-03ADF
expect 3 output
1. AAK-20250364-153865-Trik-10
2. 03ADF-Trik-10
3. 03ADF
Please guide me for solve it by use regex
Thankyou

Hi @Stef_99
Check below:

For Case 1 (AAK-20250314-154055-Trik-4_02SAA):

  • For Output 1: output1 = System.Text.RegularExpressions.Regex.Match(inputString, "^([A-Za-z0-9-]+-[A-Za-z0-9-]+-[A-Za-z0-9-]+-[A-Za-z0-9-]+-[0-9]+)").Groups(1).Value
  • For Output 2: output2 = System.Text.RegularExpressions.Regex.Match(inputString, "([A-Za-z0-9]+-[A-Za-z0-9]+)-([A-Za-z0-9]+$)").Groups(1).Value + "-" + System.Text.RegularExpressions.Regex.Match(inputString, "([A-Za-z0-9]+-[A-Za-z0-9]+)-([A-Za-z0-9]+$)").Groups(2).Value
  • For Output 3: output3 = System.Text.RegularExpressions.Regex.Match(inputString, "([A-Za-z0-9]+$)").Groups(1).Value

For Case 2 (AAK-20250364-153865-Trik-10_03ADF):

  • For Output 1: output1_2 = System.Text.RegularExpressions.Regex.Match(inputString2, "^([A-Za-z0-9-]+-[A-Za-z0-9-]+-[A-Za-z0-9-]+-[A-Za-z0-9-]+-[0-9]+)").Groups(1).Value
  • For Output 2: output2_2 = System.Text.RegularExpressions.Regex.Match(inputString2, "([A-Za-z0-9]+-[A-Za-z0-9]+)-([A-Za-z0-9]+$)").Groups(1).Value + "-" + System.Text.RegularExpressions.Regex.Match(inputString2, "([A-Za-z0-9]+-[A-Za-z0-9]+)-([A-Za-z0-9]+$)").Groups(2).Value
  • For Output 3: output3_2 = System.Text.RegularExpressions.Regex.Match(inputString2, "([A-Za-z0-9]+$)").Groups(1).Value

Please mark as a solution , if you found Helpful.
Thanks. Happy Automation

1 Like

Hi @Stef_99

You can also go with the below expressions

output1 = System.Text.RegularExpressions.Regex.Match(inputString, "[A-Za-z]+-\d+-\d+-[A-Za-z]+-\d+(?=_)").Value

output2 = System.Text.RegularExpressions.Regex.Match(inputString,"(?<=_)[A-Za-z0-9]+").Value+"-"+System.Text.RegularExpressions.Regex.Match(inputString,"(?<=[A-Za-z]+-\d+-\d+-)[A-Za-z]+-\d+(?=_)").Value

output3 = System.Text.RegularExpressions.Regex.Match(inputString,"(?<=_)[A-Za-z0-9]+").Value

Hope this helps

1 Like

StringSplit.zip (156.1 KB)
In this scenario, String split() seems to be simple solution rather than regex expressions. However, it can be achieved in both ways.

Please find the code snippet, I have shown using split() string function.

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