What this:
/^-?\d*(\.0*)?$/
matches is anything that is an integer (incorrectly matches a blank string though). Whereas this:
/^-?\d+(\.0*)?$/
matches an integer
- At the beginning of the variable there might be a - (the ? makes it optional). (the ^ fixes it to the start of the string)
- The \d+ makes sure that there is one or more digits (either after the - if it is there or at the beginning of the string). The way it was before it would have matched the blank string as an integer.
- next (\.0*)? lets the pattern of a . followed by zero or more 0 be included in a match as 1.0000 is still considered an integer. Though this whole thing is optional because of the ?
- lastly the $ insures that it must match the end of the string after the .000 pattern if it is there, or if not that the last thing in the string pattern matched by \d+.
but in answer to your query all you would have to do to check for just negative integers is make it so the - is not optional in the regular expression.
As always, perlretut and perlre are good reads
-enlil
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.