Split String using Regular Expressions keeping all original text

Hi, I would like to ask for your help!

Let me give you an simple example

I want to split the following string:

All blocks
will finish in the END.
Like everything in life,
everything will finish in the END.

The output I expect is the following:

Element [0] : All blocks
will finish in the END.
Element [1] : Like everything in life,
everything will finish in the END.

I am trying something like this but is removing the expression and the output is not what I expect:

pdfFileArray.Split({“in the END.”},StringSplitOptions.RemoveEmptyEntries)

Thank you,
Tiago Costa

1 Like

Hi @tfcosta,

You can use regex
Pattern :.*?END.

Regards,
Arivu :slight_smile:

1 Like

hi,
You can use this …
assign a string array to this below code
Split(“All blocks will finish in the END. Like everything in life, everything will finish in the END.”,".")

2 Likes

You can split with ". " also.

variable1.Split({"."},StringSplitOptions.None)

StringManupulations.xaml (6.0 KB)

1 Like

Hi, the issue is that the dot “.” is removed from the string elements. In that case that is always a dot, that is not an issue but if i want something like variable1.Split({"[a-z]{3} [0-9]{4}"},StringSplitOptions.None), i want to split the string when find this expression but i want to keep the expression in the string elements.

Regards

1 Like

Hi @tfcosta

I understand your requirement.
You can follow these steps:

  • Loop through the array and check if the string contains “in the END”
  • If True, then append “Element [number] :” in the same string.

Attaching a sample sequence of same.

Main.xaml (8.5 KB)

1 Like

Hi @chandu4712,

I already fixed my problem , and yes, I used a solution similar with what you suggested.

I used an “Activities.Matches” to grep all occurences of my regex and I used the same expression to split the text and inside the iteration I concat the first array elements with the second array elements and the result is the expected.

Thank you all for the help,

Best Regards

3 Likes