Skip to Content

As mentioned in my regular expressions tutorial  (parts 1  (,[ 2 |] and


), I’m more than happy that regular expressions – despite being  a relatively old technology – have finally been incorporated into ABAP as of Netweaver  2004s. In the last part of my tutorials I reviewed some of the tools that are  available in order to make and test regular expressions. If you are a seasoned  DIY person, you might want to do it yourself. There is a DIY show –in fact it’s  a commercial in disguise – on our regional TV where the handy man (called  Roger) always says: “What you do yourself is usually done better”. I won’t go  into the issue of whether that’s true or not though.

Pure  client<br>

            Anyway, there are several methods for testing  your regular expressions. For me, as a web developer, it’s a foregone  conclusion that it needs to be via a web application. You can make a mix of  ABAP and HTML(B), but I won’t go that far for this simple application. It can easily  be done via plain JavaScript. All you need is a form:</p>

          <p>The RE itself</p>

          <pre>Regular expression: <input type=”text” name=”regex” size=”75″ /><br></pre>

          <pre> </pre>

          <p>The string we want to test</p>

          <pre>String to test: <input type=”text” name=”teststring” size=”100″ /><br></pre>

          <pre> </pre>

          <p>The modifiers</p>

          <pre>All ocurences <input type=”checkbox” name=”global” value=”g” /> </pre>

          <pre>Case insensitive <input type=”checkbox” name=”insensitive” value=”i” /><br></pre>

          <p>And some JavaScript to test the RE.</p>

          <p>Test whether we checked some of the  modifiers</p>


     if (

         modifier  += “g”;

     if (document.regextest.insensitive.checked)

         modifier  += “i”;</pre>

          <p>Create an RE object with the constructor</p>

          <pre>  var regex = new RegExp(document.regextest.regex.value,modifier);</pre>

          <p>Execute that RE against the string</p>

          <pre>  var matchRE = regex.exec(document.regextest.teststring.value);</pre>

          <p>As long as we find results</p>


     while ((matchRE =  regex.exec(document.regextest.teststring.value))!= null)


          <p>We add the position and the found match in  the message  </p>

          <pre>  msg += ”
at ” + matchRE.index +  ”
for “+matchRE;</pre>

          <p> </p>

          <p>Putting it all together, it comes down to  this code.</p>



   <title>RE  tester</title>

   <SCRIPT  LANGUAGE=”JavaScript”>

             function  isMatch()


     var modifier = “”;

     if (

         modifier  += “g”;

     if (document.regextest.insensitive.checked)

         modifier  += “i”;

     regex = new  RegExp(document.regextest.regex.value,modifier);

     var matchRE;

     var msg = “”;

     while ((matchRE =  regex.exec(document.regextest.teststring.value))!= null)


          msg  += ”
at ” + matchRE.index + ”
for “+matchRE;


       if (msg != null)


             alert(“Yes, it matches” + msg);




            alert(“No, it doesn’t match”);






   <form  name=”regextest”>

             Regular  expression: <input type=”text” name=”regex”  size=”75″ /><br>

             String  to test: <input type=”text” name=”teststring”  size=”100″ /><br>

             All  ocurences <input type=”checkbox” name=”global”  value=”g” />

             Case  insensitive <input type=”checkbox” name=”insensitive”  value=”i” /><br></pre>

          <pre>             <input  type=”button” value=”Does it match?”  onclick=”isMatch()” />




          <p> </p>

          <p>The result looks like this. </p>


To report this post you need to login first.


You must be Logged on to comment or reply to a post.

  1. Peter Inotai

    Thanks for the tutorials (and for this weblog), they are really great.

    Do you have any info about the ‘ABAP Regex Toy Demo’? It’s mentioned in OSS note 917398.
    I’ll try to patch my NSP system soon, so I’ll able to check it.


      1. Peter Inotai
        Hi Eddy,

        Thanks for your feedback.

        I’ve just finished the patching (SPAM 20, ABAP SP 6-7) and found it. The program called DEMO_REGEX_TOY, it’s a nice demoprogram, similar to the ones you mentioned/showed here, but this one implemented in ABAP.


    1. Eddy De Clercq Post author

      Thanks for the additional links.
      As mentioned in the beginning of this web log, a couple of those tools are already elaborated on in the tutorial. This web log is intended for those who want to try things out by coding it. It is also a good way to show how things are done in JS.



Leave a Reply