<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: REGEX - find zip code in text in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/regex-find-zip-code-in-text/m-p/6239353#M1381920</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Florian,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;curiosity persists.&lt;/P&gt;&lt;P&gt;After some playing around I reduced the pattern using Placeholder for any single digit \d. Then I noticed that the 5-digit-sequence will also match 5 digits out of 6, so i used \D Placeholder for any character other than a digit Then I don't know how to recognize (optional) line start or end as alternative to non-digit, so I just enclose the string to be checked into spaces - please suggest a more elegant solution.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My test form&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;FORM regex .
  DATA:
    lv_subm   type string,
    lt_string TYPE TABLE OF string.
  FIELD-SYMBOLS:
    &amp;lt;string&amp;gt;  TYPE string.
  APPEND:
    'D-12345 Mainz' TO lt_string,
    'D 12345 Mainz' TO lt_string,
    '12345 Mainz'   TO lt_string,
    '12345Mainz'    TO lt_string,
    '123456Mainz'    TO lt_string,
    '123 45Mainz'    TO lt_string,
    'Mainz D-12345' TO lt_string.
  LOOP AT lt_string ASSIGNING &amp;lt;string&amp;gt;.
    clear:
      lv_subm.
    CONCATENATE ` ` &amp;lt;string&amp;gt; ` ` into &amp;lt;string&amp;gt;.
    FIND REGEX '\D(\d{5})\D' IN &amp;lt;string&amp;gt; SUBMATCHES lv_subm.
    WRITE: / &amp;lt;string&amp;gt;, 20 'matches', 30 lv_subm,40 'SY-SUBRC=', sy-subrc.
  ENDLOOP.
ENDFORM.                    " REGEX&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;creates this output:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt; D-12345 Mainz     matches   12345     SY-SUBRC=     0
 D 12345 Mainz     matches   12345     SY-SUBRC=     0
 12345 Mainz       matches   12345     SY-SUBRC=     0
 12345Mainz        matches   12345     SY-SUBRC=     0
 123456Mainz       matches             SY-SUBRC=     4
 123 45Mainz       matches             SY-SUBRC=     4
 Mainz D-12345     matches   12345     SY-SUBRC=     0&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As I do not fully understand the meaning of FIRST OCCURRENCE, I just removed it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Clemens&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 03 Oct 2009 15:29:52 GMT</pubDate>
    <dc:creator>Clemenss</dc:creator>
    <dc:date>2009-10-03T15:29:52Z</dc:date>
    <item>
      <title>REGEX - find zip code in text</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/regex-find-zip-code-in-text/m-p/6239348#M1381915</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi experts!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have to find the zip code (for germany) in a given text. I found 5 digits in my text, but my problem is to ignore numbers which consists of more than 5 digits!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My first try works for all cases but not for the last one.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;FIND FIRST OCCURRENCE OF REGEX '([0-9]{5})' IN ld_string SUBMATCHES ld_plz.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;D-12345 Mainz -&amp;gt; should match 12345&lt;/P&gt;&lt;P&gt;D 12345 Mainz -&amp;gt; should match 12345&lt;/P&gt;&lt;P&gt;12345 Mainz -&amp;gt; should match 12345&lt;/P&gt;&lt;P&gt;12345Mainz -&amp;gt; should match 12345&lt;/P&gt;&lt;P&gt;Mainz D-12345  -&amp;gt; should match 12345&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;D-123 45 Mainz -&amp;gt; error because of the space between the numbers&lt;/P&gt;&lt;P&gt;D-12333345 Mainz -&amp;gt; error because only 5 digits are valid for a germany zip code; my REGEX does not work!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks a lot!&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Florian&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Oct 2009 22:31:20 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/regex-find-zip-code-in-text/m-p/6239348#M1381915</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-10-02T22:31:20Z</dc:date>
    </item>
    <item>
      <title>Re: REGEX - find zip code in text</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/regex-find-zip-code-in-text/m-p/6239349#M1381916</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;D-123 45 Mainz -&amp;gt; error because of the space between the numbers&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;find ` ` in LD_STRING. " ` `  is back quotes (quote beside 1 in keyboard) 
if sy-subrc = 0
  message 'error, space not allowed'.
endif&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and  for this&lt;/P&gt;&lt;P&gt;D-12333345 Mainz -&amp;gt; error because only 5 digits are valid for a germany zip code; &lt;/P&gt;&lt;P&gt;i guess your code is correct. but you can try removing the ( )s&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;find regex '[0-9]{5}' in ld_string.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Oct 2009 22:37:44 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/regex-find-zip-code-in-text/m-p/6239349#M1381916</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-10-02T22:37:44Z</dc:date>
    </item>
    <item>
      <title>Re: REGEX - find zip code in text</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/regex-find-zip-code-in-text/m-p/6239350#M1381917</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Where's the question?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think the introduction of REGEX in ABAP is revolutionray!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Clemens&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Oct 2009 23:29:09 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/regex-find-zip-code-in-text/m-p/6239350#M1381917</guid>
      <dc:creator>Clemenss</dc:creator>
      <dc:date>2009-10-02T23:29:09Z</dc:date>
    </item>
    <item>
      <title>Re: REGEX - find zip code in text</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/regex-find-zip-code-in-text/m-p/6239351#M1381918</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Florian check this :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;FIND FIRST OCCURRENCE OF REGEX '^([0-9]{5})$' IN ld_string SUBMATCHES ld_plz.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Oct 2009 23:43:22 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/regex-find-zip-code-in-text/m-p/6239351#M1381918</guid>
      <dc:creator>former_member156446</dc:creator>
      <dc:date>2009-10-02T23:43:22Z</dc:date>
    </item>
    <item>
      <title>Re: REGEX - find zip code in text</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/regex-find-zip-code-in-text/m-p/6239352#M1381919</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi J@Y!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That's what I tried first. But unfortunately it does not seem to work. I tested it with DEMO_REGEX_TOY and it does not match in any case!? I wonder why!? I think that ^ and $ stands the start and the end of the hole content in the variable LD_STRING. It only matches &lt;STRONG&gt;12345&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Florian&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 03 Oct 2009 07:29:09 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/regex-find-zip-code-in-text/m-p/6239352#M1381919</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-10-03T07:29:09Z</dc:date>
    </item>
    <item>
      <title>Re: REGEX - find zip code in text</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/regex-find-zip-code-in-text/m-p/6239353#M1381920</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Florian,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;curiosity persists.&lt;/P&gt;&lt;P&gt;After some playing around I reduced the pattern using Placeholder for any single digit \d. Then I noticed that the 5-digit-sequence will also match 5 digits out of 6, so i used \D Placeholder for any character other than a digit Then I don't know how to recognize (optional) line start or end as alternative to non-digit, so I just enclose the string to be checked into spaces - please suggest a more elegant solution.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My test form&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;FORM regex .
  DATA:
    lv_subm   type string,
    lt_string TYPE TABLE OF string.
  FIELD-SYMBOLS:
    &amp;lt;string&amp;gt;  TYPE string.
  APPEND:
    'D-12345 Mainz' TO lt_string,
    'D 12345 Mainz' TO lt_string,
    '12345 Mainz'   TO lt_string,
    '12345Mainz'    TO lt_string,
    '123456Mainz'    TO lt_string,
    '123 45Mainz'    TO lt_string,
    'Mainz D-12345' TO lt_string.
  LOOP AT lt_string ASSIGNING &amp;lt;string&amp;gt;.
    clear:
      lv_subm.
    CONCATENATE ` ` &amp;lt;string&amp;gt; ` ` into &amp;lt;string&amp;gt;.
    FIND REGEX '\D(\d{5})\D' IN &amp;lt;string&amp;gt; SUBMATCHES lv_subm.
    WRITE: / &amp;lt;string&amp;gt;, 20 'matches', 30 lv_subm,40 'SY-SUBRC=', sy-subrc.
  ENDLOOP.
ENDFORM.                    " REGEX&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;creates this output:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt; D-12345 Mainz     matches   12345     SY-SUBRC=     0
 D 12345 Mainz     matches   12345     SY-SUBRC=     0
 12345 Mainz       matches   12345     SY-SUBRC=     0
 12345Mainz        matches   12345     SY-SUBRC=     0
 123456Mainz       matches             SY-SUBRC=     4
 123 45Mainz       matches             SY-SUBRC=     4
 Mainz D-12345     matches   12345     SY-SUBRC=     0&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As I do not fully understand the meaning of FIRST OCCURRENCE, I just removed it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Clemens&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 03 Oct 2009 15:29:52 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/regex-find-zip-code-in-text/m-p/6239353#M1381920</guid>
      <dc:creator>Clemenss</dc:creator>
      <dc:date>2009-10-03T15:29:52Z</dc:date>
    </item>
    <item>
      <title>Re: REGEX - find zip code in text</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/regex-find-zip-code-in-text/m-p/6239354#M1381921</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Do not try to put everything in one regex, it makes them non performant, hard to read and hart to maintain.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As a first approach i would add word boundaries:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
FIND FIRST OCCURRENCE OF REGEX '(\&amp;lt;[0-9]{5}\&amp;gt;)' IN ld_string SUBMATCHES ld_plz.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This fixes most of your examples but 12345Mainz not because the numbers do not have a word boundary.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If the regex above wouldfail, i would try another regex which fits the last remaining exmaple, maybe in alist with user approval.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 06 Oct 2009 05:53:05 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/regex-find-zip-code-in-text/m-p/6239354#M1381921</guid>
      <dc:creator>rainer_hbenthal</dc:creator>
      <dc:date>2009-10-06T05:53:05Z</dc:date>
    </item>
  </channel>
</rss>

