Removing repeated words from text string

In this recipe, we will use the start and end of word operators along with the subgroup register placeholders in order to write a program that will remove adjacent duplicate words from a text string. For example, from the text 'this this is is a repeated text text 11 11', the duplication of words will be removed and the new text 'this is a repeated text 11' is given as the output.

How to do it...

In order to create a repeated word removal program, proceed as follows:

  1. Declare the textstream string. Then assign some text to it that has repeated words in it.
  2. A replace all occurrences statement is then written with the regular expression (\<\w+\>) \1. The replacement key is '$1'.
  3. The if statement is then used for ...

Get SAP ABAP Advanced Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.