Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
Showing results for 
Search instead for 
Did you mean: 
This is the first in a series of six blogs describing how to enhance the regular expression tester known as Regex Toy, each blog describing a single enhancement to its capabilities.

Note: The use of the words “enhance” and “enhancement” in the sentence above is not intended to suggest that the standard SAP Enhancement Framework is involved in facilitating what is described in this series of blogs.  Also, for reasons that will be explained in the final blog, the enhancements discussed in this six-blog series do not apply to NetWeaver release 7.55 (a.k.a CE 2008/OP 2020) and beyond.


In 2015 I wrote an E-bite for SAP PRESS titled Regex in ABAP: Pattern Matching with Regular Expressions, which became the first E-bite on a programming topic. Since June 2022 it is no longer available for purchase from the SAP PRESS website.

That E-bite included a chapter describing the following four regular expression testers:

  • Regex Storm (CAUTION: the corresponding link is not a secure connection)

Regex Toy is included with a NetWeaver system and, as far as I know, is the only ABAP-based regular expression tester. Its presentation screen at that time looked like this:

As I noted in the E-bite about Regex Toy:

… an upper Input section provides a Regex field accepting a RegEx pattern, and a lower Text section accepts the text to be subjected to the RegEx pattern. Matching results are shown in the Matches section following the Input section, but requires the user either to select a radio button corresponding to one of the commands in the Options section or to press the Enter key while the cursor is positioned in the Regex or Replacement fields preceding the Options section. The matching results area has a white background; those strings matching the RegEx pattern are shown using a bold red foreground text font, while non-matching text is shown with a non-bold black foreground text font.

This is a magnificent tool by which the nuances of RegEx behavior in ABAP can be tested prior to applying a pattern to productive code under development. ... this utility not only indicates whether a string of text has any matches with the specified RegEx pattern but also shows in context where these matches occur.


An article published by the author of Regex Toy includes a disclaimer that it isn’t so much a tool but merely a toy. However, after you try it, you might agree that the author is being too modest regarding its usefulness and applicability as a development aid.

All of the other three regular expression testers noted above are available via the Internet, and I found Regex Storm to be the most useful of them. During the time I spent composing the content of the E-bite, I decided to experiment with a copy of Regex Toy, changing its source code to determine whether I could make it behave more like Regex Storm. Once I was satisfied with the result I decided to include the necessary set of Regex Toy patches in its own chapter in the E-bite so that readers could apply them at their site to make their Regex Toy also behave like Regex Storm.


Fast forward to February 2023 and I found myself at a site where yet again I wanted to apply to a copy of Regex Toy the patches I had described in the E-bite. To my horror, I found that some of those patches either no longer worked or described the placement of a patch in code that no longer looked as it did when I was writing the E-Bite.

Back in 2015, when first devising the patches to be applied to Regex Toy, I had available to me a NetWeaver 7.4 system, but now in 2023 I have available a 7.5 system. A quick look at the attributes of the Regex Toy source code indicated that the program, first released in 2006, now had a change date of June 2015 – two months prior to the E-bite becoming available. In a 7.5 system its presentation screen had been changed to look like this:

Notice that the Options block now contains a new checkbox titled IN TABLE. Also, the titles of the radio buttons in the Options block were converted to upper case, with the former option named Match now named FIND ^...$, as shown in the comparison below:

Options block with 7.4 version:

Options block with 7.5 version:

A mistake I made when describing these Regex Toy patches in the E-bite was neglecting to provide any indication about the version of the code to which they applied. Accordingly, the patches described in this blog series apply to the ABAP repository object DEMO_REGEX_TOY having a last changed date of 06/01/2015.

The reason for the first patch

  • Unlike Regex Storm, Regex Toy does not observe trailing blanks specified in the regular expression pattern.

Fire up Regex Storm using your favorite web browser, then copy and paste the following tongue twister into the Input block:

A skunk sat on a stump.  The skunk thunk the stump stunk and the stump thunk the skunk stunk.

Be certain to copy it exactly as shown, with capitalization starting each first word of a sentence, periods ending the two sentences and two spaces separating the end of the first sentence from the start of the second.

Then in the Pattern block specify the value “k “ - that is, the lower-case letter “k” followed by a single space. It should show the following:

As you can see in the screen shot above, it uses alternating green and blue background coloring to highlight each occurrence in the tongue twister where the lower-case letter “k” is followed immediately by a space. Remove the trailing space and all the letter “k”s will be highlighted.

Before applying the first patch

Now fire up Regex Toy, then:

  • Paste the same tongue twister into the Text block.

  • Place a check mark into the IN TABLE check box.

  • Select the All Occurrences button.

  • Specify in the Regex slot of the Input block the value “k “, as had been specified with Regex Storm.

  • Press enter.

It is important that your cursor remain in the Regex block following the space you typed into the second character position:

As shown in the screen shot above, you should find that it does not observe the trailing space in the Regex slot because all lower-case letter “k”s are highlighted, even those not followed by a space.

Applying the first patch

Using your favorite ABAP editor, make a copy of ABAP repository object DEMO_REGEX_TOY, selecting to copy all of its associated components when prompted, then place the series of lines shown below into method main ahead of the line clearing sub1 through sub6 (first and last lines, shown preceding and succeeding a comment line of all hyphens, already exist in the code as lines 79 and 80, respectively):
079      ENDIF.
" ------------------------------------
" DEMO_REGEX_TOY enhancement #1
" Enable explicit trailing spaces in pattern:
data : trailing_space type int4
, pattern_length type int4
if sy-curow eq 02.
trailing_space = sy-cucol - 16.
pattern_length = strlen( pattern ).
subtract pattern_length from trailing_space.
while trailing_space gt 00.
concatenate pattern
into pattern
respecting blanks.
subtract 01 from trailing_space.
" ------------------------------------
080 CLEAR: sub1, sub2, sub3, sub4, sub5, sub6.

This is the same first patch unchanged from the E-bite.

After applying the first patch

Now activate the program, execute it, and repeat the process used before:

  • Paste the same tongue twister into the Text block.

  • Place a check mark into the IN TABLE check box.

  • Select the All Occurrences button.

  • Specify in the Regex slot of the Input block the value “k “, as had been specified with Regex Storm.

  • Press enter.

As shown in the screen shot above, you should find that now it does observe the trailing space in the Regex slot because only lower-case letter “k”s followed by a space are highlighted.

What’s next?

Whereas the first patch provides an improvement to Regex Toy by enabling trailing spaces to be observed as part of the matching pattern, it still is less than optimal because matches found by Regex Toy are highlighted using a bold red foreground text font, which means there is no highlighting applied to the spaces found matching the pattern. This issue is addressed in the next blog in this series, Enhancing Regex Toy – Part 2.
Labels in this area