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.
cancel
Showing results for 
Search instead for 
Did you mean: 
This is the third 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.

Before applying the third patch


The preceding blog in this series described how to patch a copy of Regex Toy to enable it to identify spaces matching the regular expression pattern, but ended with a description of an issue where Regex Toy does not find pattern matches where the text supplied in the Text block implicitly straddles line breaks. To illustrate this problem again, execute the enhanced Regex Toy and follow these steps:

  • Paste the following tongue twister into the Text block:


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




  • 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 following string


the skunk




  • Press enter.



As shown in the screen shot above, it finds only one of the two occurrences of the regular expression pattern. The second occurrence starts at the end of the first line and continues onto the next line.

Now do the same with Regex Storm, selecting the checkbox for Ignore Case:


Perhaps that is not a fair comparison because the string “the skunk” in the tongue twister does not implicitly straddle lines in the Regex Storm example above. This is easily rectified by by placing as many spaces after the final word “thunk” such that the final string “the skunk” does straddle two lines in Regex Storm:


As shown in the screen shot above, now the second occurrence of “the skunk” does straddle two lines, and it is found and highlighted accordingly by Regex Storm.

The reason for the third patch



  • Unlike Regex Storm, Regex Toy does not enable string matching across implicit line breaks.


Applying the third patch


Using your favorite ABAP editor, edit the copy of ABAP repository object DEMO_REGEX_TOY containing the previous patches and apply the following 4-step change:

The first change is to be applied in method init:

1. Change line



wordwrap_to_linebreak_mode = cl_gui_textedit=>true.

to



wordwrap_to_linebreak_mode = cl_gui_textedit=>false.

The remaining changes are to be applied in method main:

2. Comment out the SPLIT statement following the statement



cl_gui_cfw=>flush( ).

3. Change the IN TABLE clauses of all FIND and REPLACE … IN TABLE … statements (six in all) in the TRY-ENDTRY block from



... IN TABLE result_it ...

to



... IN text_wa ...

4. Copy the commented SPLIT statement (commented out in step 2 above) and place it ahead of the display( ) statement as an active line.


This is the same third patch unchanged from the E-bite. However, if your system is NetWeaver 7.5, then that is not the end of the required changes. The TRY statement of the TRY-ENDTRY block referenced in step 3 above now appears in the patched version of this program on line 101 and is followed by an IF statement on line 102:
101      TRY.
102 IF in_table = ‘X’.

This IF statement did not exist in the NetWeaver 7.4 version. The variable is new in the Regex Toy selection screen definition and correlates to the new IN TABLE checkbox appearing in the Options block:


After applying all the changes noted above in steps 1 through 4, you now should see an ELSE statement on line 124 and its ENDIF on line 149. Much of this code is a copy of the same six FIND and REPLACE statements you just changed according to step 3 above, but in these cases the statements do not include the word TABLE following their IN clauses.. All of these statements also will require the same relative change, this time replacing the operand result_string with text_wa.

Aside: In the E-bite, I had mentioned this about Regex Toy ...


If you click the Documentation about Regular Expressions button at the top of the screen, you’re taken to the standard SAP online documentation on RegExes.


At that time, prior to the introduction of the IN TABLE checkbox, all of the capabilities offered by Regex Toy seemed to be intuitive, so I was unconcerned about its lack of documentation describing the utility itself. But now with the introduction of the IN TABLE checkbox, it is no longer so intuitive; a user would have no reason to understand what capability of regular expressions this checkbox controls. The new IF statement noted above is one of two places where the corresponding in_table variable controls the processing:






    • When checked it causes 1) the lines of specified Text, already placed into corresponding rows of an internal table of type string, to use the IN TABLE variation of the FIND and REPLACE statements to perform the regular expression processing, as well as 2) replacing each space in the text with its correct HTML code counterpart: “ ”. This corresponds to the way the utility behaved in NetWeaver 7.4.

    • When not checked it causes 1) those internal table rows to be concatenated into a single string variable on which the FIND and REPLACE statements operate, as well as 2) leaving spaces in the text unchanged.




I’ll have more to say about this checkbox at the end of this blog.



After applying the third patch


Now activate the program and execute it using the same process described previously:

  • Paste the following tongue twister into the Text block:


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




  • 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 following string


the skunk




  • Press enter.



As shown in the screen shot above, you should find that now it finds both occurrences of the string “the skunk” and highlights them accordingly.

What’s next?


Whereas the third patch provides an improvement to Regex Toy by enabling it to observe matches in the text implicitly straddling line breaks, the Matches block is now formatted such that the text runs beyond the visible portion of the screen and a horizontal scroll bar appears beneath it.

Indeed, if you were to remove the check mark from the IN TABLE checkbox, you will see that the Matches text does not exceed the screen width, meaning that its formatting is controlled by whether or not the IN TABLE checkbox is checked. But if you look closely, the text in the Matches block no longer contains two consecutive spaces separating the two sentences. This formatting behavior of losing consecutive spaces when the IN TABLE checkbox remains unchecked also is apparent in the copied DEMO_REGEX_TOY program.

The issue of the text in the Matches block losing consecutive spaces from the text supplied in the Text block when IN TABLE is checked was not an issue when I wrote the E-bite because this checkbox was not available in the version of Regex Toy I had at that time, but I will have more to say about it in the final blog in this series.

Meanwhile, the issue of text in the Matches block exceeding the visible portion of the Matches window, which now is accompanied by a horizontal scroll bar, is addressed in the next blog in this series, Enhancing Regex Toy – Part 4.