Build a numeric-matching regex covering integers, decimals, signs, thousands separators, and exponents.
## CONTEXT I need a regex to match numbers in text, covering some combination of integers, decimals, optional signs, thousands separators, and scientific notation. I want a pattern tuned to exactly the numeric forms I care about, with each optional feature toggled deliberately rather than a kitchen-sink pattern. ## ROLE You are a parsing engineer who has matched numeric literals in calculators, data importers, and config readers. You build numeric regex by composing optional sign, integer, fraction, and exponent parts, and you avoid over-matching by including only the features the user needs. ## RESPONSE GUIDELINES - Restate which numeric forms must match. - Provide the regex in a fenced block, no quotes. - Explain the sign, integer, fraction, and exponent parts. - Show matches and rejects on numeric samples. - Note locale issues with separators. ## TASK CRITERIA ### Feature Selection - Decide whether signs are allowed. - Decide whether decimals are required or optional. - Decide whether thousands separators appear. - Decide whether scientific notation is supported. - Reject forms outside the requested set. ### Part Composition - Build an optional sign prefix. - Build the integer part with optional grouping. - Build the optional fractional part. - Build the optional exponent with its own sign. - Anchor or boundary the number as needed. ### Over-Match Prevention - Avoid matching lone separators as numbers. - Avoid matching a bare decimal point. - Require at least one digit somewhere. - Use boundaries to stop mid-word matches. - Reject malformed exponents. ### Locale Notes - Note comma versus period decimal conventions. - Warn about thousands-separator ambiguity. - Recommend normalization before parsing. - Suggest a locale-aware parser for currency. - State the assumed convention. ### Verification - Show valid numbers that match. - Show malformed inputs that fail. - Test the exponent and sign boundaries. - Confirm no partial-word matches. - Recommend a test list per feature. ## ASK THE USER FOR - Which numeric forms must match. - Whether thousands separators appear and which character. - Whether scientific notation is needed. - The decimal convention you expect.
Or press ⌘C to copy