<?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 Perl : Numeric Range Pattern Matching in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-numeric-range-pattern-matching/m-p/4829253#M641641</link>
    <description>&lt;P&gt;hi Experts&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;just wondering if you can help me if i want to check a number between specific range&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if i have an ip address , how can i say the valid number for ip between 1 to 254&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;something like this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if ($ip ) =~ /[1-254].[1-254].[1-254].[1-254]/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;</description>
    <pubDate>Sun, 17 Jul 2011 11:14:52 GMT</pubDate>
    <dc:creator>doubando</dc:creator>
    <dc:date>2011-07-17T11:14:52Z</dc:date>
    <item>
      <title>Perl : Numeric Range Pattern Matching</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-numeric-range-pattern-matching/m-p/4829253#M641641</link>
      <description>&lt;P&gt;hi Experts&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;just wondering if you can help me if i want to check a number between specific range&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if i have an ip address , how can i say the valid number for ip between 1 to 254&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;something like this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if ($ip ) =~ /[1-254].[1-254].[1-254].[1-254]/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;</description>
      <pubDate>Sun, 17 Jul 2011 11:14:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-numeric-range-pattern-matching/m-p/4829253#M641641</guid>
      <dc:creator>doubando</dc:creator>
      <dc:date>2011-07-17T11:14:52Z</dc:date>
    </item>
    <item>
      <title>Re: Perl : Numeric Range Pattern Matching</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-numeric-range-pattern-matching/m-p/4829293#M641642</link>
      <description>&lt;P&gt;Probably...have you tested it??&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;you made no statement regarding the cleanliness of your data, so it's difficult to impossible to know how to answer your question.&amp;nbsp; are you always going to have IPv4 format addresses?&amp;nbsp; what about netmasks?&amp;nbsp; what about some the of "exception" IP addresses?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if your want to rigorously test your IP address, i suggest you install &lt;A title="NetAddr::IP" href="http://search.cpan.org/~miker/NetAddr-IP-4.044/IP.pm" target="_blank"&gt;NetAddr::IP.&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;to take a peek at a conversation were this question was already asked, head over to &lt;A href="http://www.perlmonks.org/?node_id=380565" title="perlmonks" target="_blank"&gt;perlmonks.&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 17 Jul 2011 13:25:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-numeric-range-pattern-matching/m-p/4829293#M641642</guid>
      <dc:creator>donna hofmeister</dc:creator>
      <dc:date>2011-07-17T13:25:23Z</dc:date>
    </item>
    <item>
      <title>Re: Perl : Numeric Range Pattern Matching</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-numeric-range-pattern-matching/m-p/4829311#M641643</link>
      <description>&lt;P&gt;Hi:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There are a number of things wrong with your approach.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1.&amp;nbsp; A dot character will match anything, so you need to escape it.&lt;/P&gt;&lt;P&gt;2.&amp;nbsp; Character class ranges are single ranges from first to the second single character.&lt;/P&gt;&lt;P&gt;3.&amp;nbsp; You should anchor your match to avoid false matches as with a string that began with "1234.".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In all, there is a better alternative to rolling your own in this case:&amp;nbsp; 'Regexp::Common:net'.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Consider this example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;# cat ./verifyip&lt;/P&gt;&lt;P&gt;#!/usr/bin/perl&lt;BR /&gt;use strict;&lt;BR /&gt;use warnings;&lt;BR /&gt;use Regexp::Common qw( net );&lt;BR /&gt;while (&amp;lt;&amp;gt;) {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; chomp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if ( /^$RE{net}{IPv4}$/ ) {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "$_ is valid\n";&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "$_ is not a valid IPv4 address\n";&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR /&gt;}&lt;BR /&gt;1;&lt;BR /&gt;﻿&lt;/P&gt;&lt;P&gt;Regards!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;...JRF...&lt;/P&gt;</description>
      <pubDate>Sun, 17 Jul 2011 14:05:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-numeric-range-pattern-matching/m-p/4829311#M641643</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2011-07-17T14:05:12Z</dc:date>
    </item>
    <item>
      <title>Re: Perl : Numeric Range Pattern Matching</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-numeric-range-pattern-matching/m-p/4829345#M641644</link>
      <description>&lt;P&gt;Hi (again):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm happy to have helped.&amp;nbsp; Since this community is new, replacing the former ITRC, please read:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A target="_blank" href="http://h30499.www3.hp.com/t5/help/faqpage/faq-category-id/kudos#kudos"&gt;http://h30499.www3.hp.com/t5/help/faqpage/faq-category-id/kudos#kudos&lt;/A&gt;﻿&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;...JRF...&lt;/P&gt;</description>
      <pubDate>Sun, 17 Jul 2011 15:55:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-numeric-range-pattern-matching/m-p/4829345#M641644</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2011-07-17T15:55:55Z</dc:date>
    </item>
    <item>
      <title>Re: Perl : Numeric Range Pattern Matching</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-numeric-range-pattern-matching/m-p/4829387#M641645</link>
      <description>&lt;P&gt;Basically you can't check ranges, only patterns.&amp;nbsp; To exclude 0 and 255, you would have to do extra work.&lt;/P&gt;&lt;P&gt;It might be easier to crack the 4 numeric values and then do a numeric range check.&lt;/P&gt;</description>
      <pubDate>Sun, 17 Jul 2011 19:24:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-numeric-range-pattern-matching/m-p/4829387#M641645</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2011-07-17T19:24:41Z</dc:date>
    </item>
    <item>
      <title>Re: Perl : Numeric Range Pattern Matching</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-numeric-range-pattern-matching/m-p/4830469#M641646</link>
      <description>&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; &amp;nbsp;/[1-254].[1-254].[1-254].[1-254]/﻿&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;James had the nice solution. And I'm pleased you marked his reply as 'solved'.&lt;/P&gt;&lt;P&gt;[ You seem to have forgotten the 'kudo', so I gave one just in case. Feel free to add more. ]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If under certain circumstanses still want to use a simple regular expression match,&lt;/P&gt;&lt;P&gt;then you can at most do something like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/\b\d{1,3}\.\d{1,3}\.﻿\d{1,3}\.﻿\d{1,3}\b/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So this just looks for a pattern with 1 to 3 &amp;nbsp;numbers, a dot, 1 to 3 numbers and other dot and so on.&lt;/P&gt;&lt;P&gt;The \b requests a 'boundary', like a word, or begin of end of line.&lt;/P&gt;&lt;P&gt;The leading \b fill fails patterns like &amp;nbsp; test1.2.3.4&lt;/P&gt;&lt;P&gt;and the trailing \b stops patterns like 1.2.3.4test&lt;/P&gt;&lt;P&gt;The test above incorrectly fails 0123.2.3.4 which is legal, but that serves 'm right imho.&lt;/P&gt;&lt;P&gt;It does NOT check the 255 range though.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;Hein&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jul 2011 14:12:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-numeric-range-pattern-matching/m-p/4830469#M641646</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2011-07-18T14:12:39Z</dc:date>
    </item>
    <item>
      <title>Re: Perl : Numeric Range Pattern Matching</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-numeric-range-pattern-matching/m-p/4830593#M641647</link>
      <description>&lt;P&gt;Hi (again):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the spiril of TIMTOWTDI , you could write:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;if ( m/^(?:\d{1,3}[.]){3}\d{1,3}$/ ) {&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;...which says:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Match, but don't capture (because we don't need to and its faster than capturing) three repetions of one-to-three digits anchored to the beginning of the field or line being matched:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;^(?:\d{1,3}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;...followed by a dot:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;[.]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;...and do this three times:&lt;/P&gt;&lt;P&gt;){3}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;...followed by a digit one-to-three times, anchored to the end of the line or field:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;\d{1,3}$&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;﻿The downside, as I originally hinted, if you played a bit with the use of 'Regexp::Common::net', is that the Perl module would *not* consider an address like this to be valid:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;999.888.777.666&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;...JRF...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jul 2011 15:29:36 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-numeric-range-pattern-matching/m-p/4830593#M641647</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2011-07-18T15:29:36Z</dc:date>
    </item>
  </channel>
</rss>

