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: 
0 Kudos
This is the fifth 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 fifth patch


The preceding blog in this series described how to patch a copy of Regex Toy to enable it to prevent text in the Matches block from running beyond the visible area of the window, but ended with a description of an issue whereby Regex Toy now ignores explicit line breaks. To illustrate this problem again, execute the enhanced Regex Toy and follow these steps:

  • Paste the following first sentence of the tongue twister into the Text block:


A
skunk
sat
on
a
stump.


such that each word is followed by an explicit line break placing it on its own line as shown above.




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

  • Select the All Occurrences button.

  • Specify a single dot character in the Regex slot

  • Press enter.



As shown in the screen shot above, you should find that now every character of the Text matches the regular expression pattern, as it should, but now the text no longer is formatted in the Matches window with the explicit line breaks provided with the content in the Text window.

Now do the same with Regex Storm:


As shown in the screen shot above, Regex Storm does observe and retain explicit line breaks.

The reason for the fifth patch



  • Unlike Regex Storm, Regex Toy does not observe explicit line breaks when presenting the matching text in the Matches block.


Applying the fifth patch


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

1 After the TRY statement, insert the following set of lines (first and last lines, shown preceding and succeeding a comment line of all hyphens, already exist in the code as lines 101 and 102, respectively):



101      TRY.
" ------------------------------------
" DEMO_REGEX_TOY enhancement #5
" Convert two-character carriage-return/line-feed into
" single-character form feed to prevent split during
" search for any character:
replace all occurrences
of cl_abap_char_utilities=>cr_lf in text_wa
with cl_abap_char_utilities=>form_feed.
" ------------------------------------
102 IF in_table = 'X'.

2. Also, change the AT clause of the SPLIT statement, following the ENDTRY statement, from



... AT cr_lf ...

to



... AT cl_abap_char_utilities=>form_feed ...

This is nearly the same fifth patch unchanged from the E-bite other than the fact that the IF statement following the TRY statement is new with the NetWeaver 7.5 version of this utility, and that the AT clause of the SPLIT statement was changed to replace the original 7.4-version operand cl_abap_char_utilities=>cr_lf with cr_lf.

After applying the fifth patch


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

  • Paste the following first sentence of the tongue twister into the Text block:


A
skunk
sat
on
a
stump.


such that each word is followed by an explicit line break placing it on its own line as shown above.




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

  • Select the All Occurrences button.

  • Specify a single dot character in the Regex slot

  • Press enter.



As shown in the screen shot above, you should find that now Regex Toy retains and observes the explicit line breaks with the content supplied in the Text block.

What’s next?


There are no more patches from the E-bite, but in the third blog of this series we discovered that the new IN TABLE checkbox causes consecutive blanks of content in the Text block to be ignored when it is presented in the Matches block. So let’s execute Regex Toy using a scenario that illustrates this behavior:

  • 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 a dot in the Regex slot of the Input block.

  • Press enter.



As shown in the screen shot above, you should find that Regex Toy determines every character of the Text block matches the pattern specified in the Regex slot, illustrating this using alternating green and blue background highlighting of each character in the Matches block. Notice especially that there are 2 spaces between the two sentences, each one shown with a different background color highlighting.

Now remove the check mark from the IN TABLE checkbox.


As shown in the screen shot above, you should find that Regex Toy still determines every character of the Text block matches the pattern specified in the Regex slot, but presents only a single space between the two sentences in the Matches block. Indeed, checking and unchecking the IN TABLE checkbox in rapid succession will clearly indicate the difference between the Matches block having a single space or pair of spaces separating the two sentences. This issue is addressed in the next blog in this series, Enhancing Regex Toy – Part 6.