Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Patterns for your numbers

by bronto (Priest)
on Feb 07, 2003 at 11:03 UTC ( #233432=perlquestion: print w/ replies, xml ) Need Help??
bronto has asked for the wisdom of the Perl Monks concerning the following question:

Starting to elucubrate from these nodes and perlnumber, I am wondering: which pattern (or patterns) cover any possible valid string representation of a number in Perl, leaving version numbers out?

What about these?

  • Integer: ^\s*[+-]?\d+\s*$
  • Binary: ^\s*[+-]?0b[0-1]+\s*$
  • Octal: ^\s*[+-]?0[0-7]+\s*$
  • Hexadecimal: ^\s*[+-]?0x[0-9a-fA-F]+\s*$
  • With decimals: ^\s*[+-]?\d+\.\d*\s*$
  • Exponential: ^\s*[+-]?\d+(\.\d*)?[Ee][+-]?\d+$

Ciao!
--bronto


The very nature of Perl to be like natural language--inconsistant and full of dwim and special cases--makes it impossible to know it all without simply memorizing the documentation (which is not complete or totally correct anyway).
--John M. Dlugosz

Comment on Patterns for your numbers
Select or Download Code
Re: Patterns for your numbers
by adrianh (Chancellor) on Feb 07, 2003 at 11:13 UTC

      Thanks for the link, adrianh, it's on my notepad now.

      Anyway, as I said in the question, I am not looking for a module, nor I am looking for such a grainlevel control over "numeric strings".

      Call it a challenge (if you like): are those patterns ok? Would you write them differently for the sake of {efficiency|compactness|speed|readability|anything}? Would you compact all af them in a unique, catchall regex?

      That was the question.

      Please, don't feel offended about that: pointers to modules that do the job are useful and I don't despise them. But they are not an answer to the question

      Ciao!
      --bronto


      The very nature of Perl to be like natural language--inconsistant and full of dwim and special cases--makes it impossible to know it all without simply memorizing the documentation (which is not complete or totally correct anyway).
      --John M. Dlugosz
Re: Patterns for your numbers
by jryan (Vicar) on Feb 07, 2003 at 16:19 UTC
    Take a read at this entry in perlfaq4.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://233432]
Approved by adrianh
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (18)
As of 2014-08-27 20:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (252 votes), past polls