<?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 IP validation in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/regex-ip-validation/m-p/4049901#M968089</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi a®s, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can see a lot of example here &lt;A href="http://www.regular-expressions.info/examples.html"&gt;regular-expressions.info&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;We can find the follow sample:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;"&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;IP Addresses&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;- Matching an IP address is another good example of a trade-off between regex complexity and exactness. &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt; d{1,3}.d{1,3}.d{1,3}.d{1,3} &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt; will match any IP address just fine, but will also match 999.999.999.999 as if it were a valid IP address. Whether this is a problem depends on the files or data you intend to apply the regex to. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;- To restrict all 4 numbers in the IP address to 0..255, you can use this complex beast: &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt; (25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)  &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Analyze this regular expression with RegexBuddy (everything on a single line). The long regex stores each of the 4 numbers of the IP address into a capturing group. You can use these groups to further process the IP number.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;- If you don't need access to the individual numbers, you can shorten the regex with a quantifier to: &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt; (?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?) &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt; Analyze this regular expression with RegexBuddy. Similarly, you can shorten the quick regex to &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt; (?:d{1,3}.){3}d{1,3} &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt; Analyze this regular expression with RegexBuddy&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;"&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Font: &lt;A href="http://www.regular-expressions.info/examples.html" target="test_blank"&gt;http://www.regular-expressions.info/examples.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Based on this examples:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can do:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
REPORT  zregex.

DATA ip TYPE string VALUE '10.10.0.10'. " Correct
DATA ip2 TYPE string VALUE '10.10.0.'. " Incorrect
DATA ip4 TYPE string VALUE '999.10.0.10'. " Incorrect

DATA validation TYPE string VALUE ' (25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?) '.

START-OF-SELECTION.

  "// Test all &amp;lt;IPx&amp;gt;
  FIND REGEX validation IN ip.

  IF sy-subrc IS NOT INITIAL.
    "// Error
  ELSE.
    "// It's OK
  ENDIF.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;As I Copy &amp;amp; Past the code from internet, please don't reward for me !&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Share ours knowledge with all is the SCN's goal&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best regards.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Marcelo Ramos&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 24 Jun 2008 19:35:37 GMT</pubDate>
    <dc:creator>marcelo_ramos1</dc:creator>
    <dc:date>2008-06-24T19:35:37Z</dc:date>
    <item>
      <title>RegEx IP validation</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/regex-ip-validation/m-p/4049898#M968086</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am using the following RegEx for validation of IP address, it is not validating &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
{^(d|[1-9]d|1dd|2[0-4]d|25[0-5]).(d|[1-9]d|1dd|2[0-4]d|25[0-5])
.(d|[1-9]d|1dd|2[0-4]d|25[0-5]).(d|[1-9]d|1dd|2[0-4]d|25[0-5])$}
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Any Info?&lt;/P&gt;&lt;P&gt;a®&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 Jun 2008 17:46:38 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/regex-ip-validation/m-p/4049898#M968086</guid>
      <dc:creator>former_member194669</dc:creator>
      <dc:date>2008-06-24T17:46:38Z</dc:date>
    </item>
    <item>
      <title>Re: RegEx IP validation</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/regex-ip-validation/m-p/4049899#M968087</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;try something else like,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;

\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope it helps,&lt;/P&gt;&lt;P&gt;Bert&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 Jun 2008 18:44:00 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/regex-ip-validation/m-p/4049899#M968087</guid>
      <dc:creator>b_deterd2</dc:creator>
      <dc:date>2008-06-24T18:44:00Z</dc:date>
    </item>
    <item>
      <title>Re: RegEx IP validation</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/regex-ip-validation/m-p/4049900#M968088</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have tried with DEMO_REGEX_TOY but it is giving "invalid regex expression"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any info?&lt;/P&gt;&lt;P&gt;a®&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 Jun 2008 19:11:22 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/regex-ip-validation/m-p/4049900#M968088</guid>
      <dc:creator>former_member194669</dc:creator>
      <dc:date>2008-06-24T19:11:22Z</dc:date>
    </item>
    <item>
      <title>Re: RegEx IP validation</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/regex-ip-validation/m-p/4049901#M968089</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi a®s, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can see a lot of example here &lt;A href="http://www.regular-expressions.info/examples.html"&gt;regular-expressions.info&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;We can find the follow sample:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;"&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;IP Addresses&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;- Matching an IP address is another good example of a trade-off between regex complexity and exactness. &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt; d{1,3}.d{1,3}.d{1,3}.d{1,3} &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt; will match any IP address just fine, but will also match 999.999.999.999 as if it were a valid IP address. Whether this is a problem depends on the files or data you intend to apply the regex to. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;- To restrict all 4 numbers in the IP address to 0..255, you can use this complex beast: &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt; (25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)  &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Analyze this regular expression with RegexBuddy (everything on a single line). The long regex stores each of the 4 numbers of the IP address into a capturing group. You can use these groups to further process the IP number.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;- If you don't need access to the individual numbers, you can shorten the regex with a quantifier to: &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt; (?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?) &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt; Analyze this regular expression with RegexBuddy. Similarly, you can shorten the quick regex to &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt; (?:d{1,3}.){3}d{1,3} &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt; Analyze this regular expression with RegexBuddy&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;"&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Font: &lt;A href="http://www.regular-expressions.info/examples.html" target="test_blank"&gt;http://www.regular-expressions.info/examples.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Based on this examples:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can do:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
REPORT  zregex.

DATA ip TYPE string VALUE '10.10.0.10'. " Correct
DATA ip2 TYPE string VALUE '10.10.0.'. " Incorrect
DATA ip4 TYPE string VALUE '999.10.0.10'. " Incorrect

DATA validation TYPE string VALUE ' (25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?) '.

START-OF-SELECTION.

  "// Test all &amp;lt;IPx&amp;gt;
  FIND REGEX validation IN ip.

  IF sy-subrc IS NOT INITIAL.
    "// Error
  ELSE.
    "// It's OK
  ENDIF.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;As I Copy &amp;amp; Past the code from internet, please don't reward for me !&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Share ours knowledge with all is the SCN's goal&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best regards.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Marcelo Ramos&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 Jun 2008 19:35:37 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/regex-ip-validation/m-p/4049901#M968089</guid>
      <dc:creator>marcelo_ramos1</dc:creator>
      <dc:date>2008-06-24T19:35:37Z</dc:date>
    </item>
    <item>
      <title>Re: RegEx IP validation</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/regex-ip-validation/m-p/4049902#M968090</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi ,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can't use this expression on REGEX Toy because the input field allows only 120 characters, and this expression is bigger than this !&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Try to test using this code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;

REPORT  zregex.

DATA ip TYPE string VALUE '10.10.0.10'.
DATA ip2 TYPE string VALUE '10.10.0.'.
DATA ip3 TYPE string VALUE '999.10.0.10'.

DATA validation TYPE string VALUE '\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b'.

START-OF-SELECTION.

  PERFORM validateip USING ip.
  PERFORM validateip USING ip2.
  PERFORM validateip USING ip3.

FORM validateip USING ip TYPE string.

  FIND REGEX validation IN ip.

  IF sy-subrc IS NOT INITIAL.
    WRITE:/ 'Ip: ', ip, ' is invalid !'.
  ELSE.
    WRITE:/ 'Ip: ', ip, ' is Valid !'.
  ENDIF.

ENDFORM.                    " validateIP

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Greetings,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Marcelo Ramos&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 Jun 2008 19:53:26 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/regex-ip-validation/m-p/4049902#M968090</guid>
      <dc:creator>marcelo_ramos1</dc:creator>
      <dc:date>2008-06-24T19:53:26Z</dc:date>
    </item>
    <item>
      <title>Re: RegEx IP validation</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/regex-ip-validation/m-p/4049903#M968091</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ramos,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thankyou. For pointing out the 120 length limit in REGEX TOY. and the useful link you provided.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now its working.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; a®&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Jun 2008 11:12:35 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/regex-ip-validation/m-p/4049903#M968091</guid>
      <dc:creator>former_member194669</dc:creator>
      <dc:date>2008-06-25T11:12:35Z</dc:date>
    </item>
    <item>
      <title>Re: RegEx IP validation</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/regex-ip-validation/m-p/4049904#M968092</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;And also i can use like the following for IP  (no check for alid values (0-255))&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/^d{1,3}.d{1,3}.d{1,3}.d{1,3}$/ 999.999.999.999&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;a®&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Jun 2008 19:13:34 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/regex-ip-validation/m-p/4049904#M968092</guid>
      <dc:creator>former_member194669</dc:creator>
      <dc:date>2008-06-25T19:13:34Z</dc:date>
    </item>
  </channel>
</rss>

