# Is this any number?

Inspired (like 2 others) by this chat message. (and to some extent, my CMC)

Given a string as an input, your task is to check whether or not that string is a number.

## What is a number?

This is a list of all input formats that are "numbers":

• Integers: An integer is a string made entirely of characters from 1234567890, without any other character e.g. 152
• Floats: A float is a integer with 1 (no more, no less) decimal points (.) in the middle of the number. A decimal point must always be preceded and followed by a number e.g. 1.0 or 3.14
• Complex: A complex number is a number that follows the format a+bj where a and b are numerical values. The plus sign can also be a minus sign e.g. 1+10j or 143-1j. If it saves bytes (or you want to), you may use i instead of j.
• Longs: A long is any number that would be classed as an integer or a float, with an L at the end e.g 1325963L
• Hexadecimal: A hexadecimal number is a number which consists entirely of characters in 1234567890abcdef. Upper case characters are valid hex, but only when used consistently e.g. 10a or afa not A5c
• Scientific: A scientific number is a number which consists of a run of digits (1234567890.) followed by an e followed by a run of digits, optionally preceded by a -. A E may also be used.

Any of these 5 may also be preceded by a minus sign (-) but any whitespace in the number causes it to no longer be a number e.g. -3.5 + 2i isn't a number. Longs may not be hexadecimal but may be floats

You must output 2 distinct values (preferably truthy and falsy but you may choose) for inputs that are either numbers as defined above, or not.

## Test Cases

These should result in truthy

10
-9.34
-3.5+2j
ab1
100000L
3.14159L
-73e-7
7E53C80
1.2e3
12E3.4


And these should be falsy

abcdefghijklmnop
10.10.10
2569LL
10L+9j
8+45io
4aE3
3.
.3


Now because small numbers are easier to work with, this is a so shortest code, in bytes, wins!

• Isn't 4E3 = 4000? – Mr. Xcoder Jul 15 '17 at 21:20
• I don't downvote, but I find these rules (only lowercase e, j and not i, single L is OK) quite arbitrary. This reads basically "design me a regex for this spec". – Uriel Jul 15 '17 at 21:23
• It seems exceedingly inconvenient to only allow the use of j rather than either i or j, so long as convention is internally consistent within the answer - as I would be willing to bet there is at least one language in which i is used to denote complex numbers - beyond this, I am aware of at least 20 languages in which E is the proper notation for scientific notation - by preventing this internal method of interpretation seems like it would artificially inflate some answers – Taylor Scott Jul 15 '17 at 21:23
• @Uriel I have changed it so that the rules are less rigid about input, and have changed the appropriate test cases. – caird coinheringaahing Jul 15 '17 at 21:30
• @TaylorScott it is. Read the part on floats again. – caird coinheringaahing Jul 15 '17 at 21:42

# SOGL V0.12, 5352 50 bytes

O[►~hΘP█⁵\↔<sK⁹>¼⅝┘d⁾Δo≡7ξδ¾▓↑ΧGj4<eu╝t┼Pπ»‘øβ!d!-


Try it Here! or test all test cases (first number indicates amount of test cases)

based on a regex - ^(-?\d+((\.\d+|)(L|e-?\d+(\.\d+|)|\+\d+(\.\d+|)j|)|)|[A-F\d]+)$ • Not sure this works for −3.5+2j or ab1 – wrymug Jul 16 '17 at 17:34 • the first one uses a unicode dash, which shouldn't be (and has been fixed in the examples), and for the second - this expects all uppercase hexadecimal – dzaima Jul 16 '17 at 17:36 # Javascript, 7271 65 bytes saved one byte thanks to @Cowsquack saved 6 bytes thanks to @dzaima a=>/^(-?\d+((\.\d+|)(L|e-?\d+(\.\d+|)|\+\d+(\.\d+|)j|)|)|[A-F\d]+)$/.test(a)


JS port of @dzaima's answer. Credit to @dzaima for the regex.

• /regex here/.test(a) is shorter than match – user41805 Jul 16 '17 at 18:05
• you don't need the ==null if you use test – dzaima Jul 16 '17 at 18:13
• Fails for lowercase hexadecimals. – darrylyeo Jul 16 '17 at 18:15
• @darrylyeo caird said in the comments that you can choose whether to support lowercase or uppercase hexadecimals – dzaima Jul 16 '17 at 18:16
• Can you simply use /regex here/.test, eliminating a=> and (a)? I'm not a Javascript programmer, but this seems to me like it would work – musicman523 Jul 16 '17 at 19:56

# Python 3, 290136 105 bytes

Python port of @dzaima's answer. All credit to @dzaima for the regex :)

lambda s:re.match('^(-?\d+((\.\d+|)(L|e-?\d+(\.\d+|)|\+\d+(\.\d+|)j|)|)|[A-F\d]+|[a-f\d]+)\$',s)
import re


Try it online!

• You don't need to account for both lowercase and uppercase hexadecimal (caird said that in the comments) – dzaima Jul 16 '17 at 17:45
• You don't need to compile the regex. – totallyhuman Jul 16 '17 at 18:00
• 111 bytes – totallyhuman Jul 16 '17 at 18:22
• @totallyhuman thanks! I don't think it needs bool() though, because the re match object is truthy. – wrymug Jul 16 '17 at 18:28
• It's 1 byte shorter as re.compile('...').match rather than lambda s:re.match('...',s) – musicman523 Jul 17 '17 at 1:32