Is it intentional that the last one's only got three parts to it? Anyhow, here's one regex that'll work:

/^(?:[\dx]{1,3}\.){0,3}[\dx]{1,3}$/

This will match between 1 and 4 blocks, each consisting of 1 to 3 digits or x's, separated by periods.

Are you dealing with IP addresses there? If so, you may also be interested in Net::IP::Match, Net::IP::Match::* and Net::IP::CMatch.

EDIT: the OP both edited his post and changed the examples of strings he'd like to match after I posted the above. For reference, this was the original post, in its entirety:

I am trying to have a Regex for a dotted number format as shown below

  • 8.1xx.x.x
  • 9.0.3xx.x
  • 9.0.4xx.x
  • . . .
  • 9.1xx.x

So any thoughts how I can make a generic regex for matching all these patterns.


In reply to Re: Regex for matching dotted numbers by AppleFritter
in thread Regex for matching dotted numbers by techman2006

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.