Hello
It might not be possible in one single activity.
It will likely require more than 1 step.
You can check out these posts:
I would suggest, when you are ready providing a sample, the expected output and tell us about the pattern of the text.
Hopefully this helps.