G'day Bill,

I'd say you're on the right track creating a regex for $number and building up a more complex regex from there. Unfortunately, you're matching some things that you shouldn't.

$ perl -E ' say "$_: ", /1?\d{1,4}/ ? "Y" : "N" for qw{240 2 3600 1 10000 0 0000 19999 999999999}; ' 240: Y 2: Y 3600: Y 1: Y 10000: Y 0: Y 0000: Y 19999: Y 999999999: Y

I'd aim for a more stringent regex for $number.

$ perl -E ' say "$_: ", /(?<![0-9])(?:10000|[1-9][0-9]{0,3})(?![0-9])/ ? "Y" : + "N" for qw{240 2 3600 1 10000 0 0000 19999 999999999}; ' 240: Y 2: Y 3600: Y 1: Y 10000: Y 0: N 0000: N 19999: N 999999999: N

The OP is somewhat unclear in that it shows an example with spaces then says spaces are removed. Stuff is also removed, whatever that refers to. There's not much we can do about that beyond requesting clarification.

I'd also add ^ and $ (or equivalent) assertions to the final regex.

— Ken


In reply to Re^2: Regex question by kcott
in thread Regex question by Umdurman

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.