Home > Mobile >  How to insert linebreak every 40 characters with Regex?
How to insert linebreak every 40 characters with Regex?

Time:11-24

I want to insert line breaks in a very long string using REPLACE ALL OCCURENCES OF REGEX. Unfortunately it does not work. It inserts the line break only one time at the very beginning then does nothing with the remaining string.

`Lorem ipsum dolor sit amet, consectetur ` &&#adipiscing elit. Proin sagittis tortor at

Here is my program.

REPORT zzz.

START-OF-SELECTION.
  DATA(gv_string) =
`Lorem ipsum dolor sit amet, consectetur ` &&
`adipiscing elit. Proin sagittis tortor a` &&
`t bibendum eleifend. Cras nisi felis, ac` &&
`cumsan vitae euismod eget, viverra sed i` &&
`psum. Integer imperdiet eleifend interdu` &&
`m. Nunc sed ultrices lectus. Sed nisi ex` &&
`, tincidunt quis arcu eget, commodo temp` &&
`or odio. In hac habitasse platea dictums` &&
`t. Nunc sit amet convallis ex, in conseq` &&
`uat velit. In suscipit orci lectus, laor` &&
`eet pretium leo molestie non. Duis trist` &&
`ique ipsum non porta faucibus. Nullam ia` &&
`culis rutrum arcu, sit amet rhoncus mass` &&
`a interdum at. Donec luctus magna metus,` &&
` et varius massa euismod vel. Nunc sem s` &&
`em, lobortis et convallis nec, aliquam e` &&
`u nunc. Nullam quis sollicitudin ante. N` &&
`ulla suscipit eu ante lobortis sodales. ` &&
`Cras mattis enim a leo pellentesque, ut ` &&
`interdum orci rutrum. Fusce varius matti` &&
`s pulvinar. Lorem ipsum dolor sit amet, ` &&
`consectetur adipiscing elit. Integer mol` &&
`estie ipsum et aliquam porttitor. Phasel` &&
`lus consectetur viverra sem. Aenean cons` &&
`equat eros eget rutrum tempus. Aliquam e` &&
`rat volutpat.`.

REPLACE ALL OCCURRENCES OF REGEX `^.{40}` IN gv_string WITH '`$0` &&\n'.
BREAK-POINT.

The regular expression ^.{40} and the replacement string I use are for sure correct, because I get the result I want for example in Notepad .

Is this some kind of a bug or is this documented somewhere as a constraint in ABAP-RegEx?

CodePudding user response:

Remove the ^ from the regex expression, to insert a line break every 40 characters:

REPLACE ALL OCCURRENCES OF REGEX `^.{40}` IN gv_string WITH '`$0` &&\n'.
  • Related