Regex for number
/-?\b\d+(?:\.\d+)?(?:[eE][+-]?\d+)?\b/g
Matches
Examples
Note
Integers, decimals and scientific notation. Thousands separators like 1,000 are two numbers here.
Matches in the example
"42""-7""3.14""6.02e23""-1.5E-3"
Token by token
-?the character “-”, optionally\ba word boundary\d+a digit (0–9), one or more times, as many as possible(?:a group, not capturing\.the character “.”\d+a digit (0–9), one or more times, as many as possible)?end of group, whole group optionally(?:a group, not capturing[eE]one of: “e” or “E”[+-]?one of: “+” or “-”, optionally\d+a digit (0–9), one or more times, as many as possible)?end of group, whole group optionally\ba word boundary
Other patterns
- Email address
- URL
- IPv4 address
- UUID
- Hex color
- Date (YYYY-MM-DD)
- Time (24-hour)
- US phone number
- Phone number (E.164)
- US ZIP code
- Credit card number
- URL slug
- Username
- Strong password
- HTML tag
- Semantic version
- MAC address
- JSON Web Token
- Hashtag
- @mention
- Number
- Leading and trailing whitespace
- Repeated word
- Blank lines
- Markdown link
- Quoted string
- Domain name
- File extension
- Base64
- Trailing comma