I'm trying to come up with a peice of regex to classify data types. The way I need to classify these data are numeric and non-numeric. And I need to sub-classify numeric as numeric w/dollar sign/plus signs/neg signs/commas/decimal point. The idea is that I'll be passing fields through this expression and it should return it's classification. To further complicate issues if a field contains something like: "100$00", it would be non-numeric. It would only be numeric if the dollar sign is at the beginning although "+$100" would be numeric as would "-$100". I've been playing with this for a couple of days, so I'm really getting frustated. Here's what I've been trying(unsuccessfully):
/^(\+)?(-)?(\$)?(\d)*(\.)?\d*$/
I realize that this is flawed and that this may not even be the best way to go about this. Also, this would only account for numeric data not the non-numeric. So I still have to take that into consideration. Whatever method I use it must be efficient as there maybe literally billions of fields being passed through this routine.
I really didn't expect this to be a real stumbling block when I projected my time estimates for this project. It seemed so trivial. I guess after 20+ years of coding (not Perl) I've gotten cocky, I should've realized by now that nothing that gets that many hits is going to be trivial.
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.