Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Okay, but first, the others are correct in having you check for your 'q' quit action first.

The '^' character says start matching from the very first character in the string. This is called an 'anchor', because you're saying the match starts at a specific place.

The '\d' means match only number characters. The translation is '[0123456789]' also seen as '[0-9]'. There are many of these shortcuts and it is worth your while to learn them (see perlre doc).

The '+' means "one or more of the preceding". So we're saying there has to be at least one numeric digit and maybe more (but contiguous - nothing in-between).

And the '$' is like '^', an anchor, saying the match ends after the last character in the string. (There's a footnote about newline chars, but look that up later).

So altogether we're saying that the entire string (because of the '^' and '$' anchors) must contain only numeric characters and there must be at least one of those, and nothing else is allowed.

Other people have mentioned playing with '+' or '-' signs and that's reasonable. It gets into the topic "what do you think a number looks like?" I know there's good discussions in lots of books. I found a bit of one in perlretut under "Building a Regexp". There's probably others in the docs.

With REs it is only a question of "How much fun can you stand at any one time?" Learn just what you need at the time and keep adding on!

In reply to Re^3: String/Numeric Manipulation by shenme
in thread String/Numeric Manipulation by Ms. T.

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

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (2)
As of 2022-05-22 10:48 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (80 votes). Check out past polls.