05AB1E, 63 61 61 62 bytes
Try it online +1 byte as bug-fix for inputs like "u"
, "l"
, "LL"
, etc. (thanks for noticing @Neil)
Try it online or verify all test casesverify all test cases.
ʒ # Filter this list by:
Å¿ # Where the (implicit) input ends with this string
}н # After the filter: only leave the first (longest) one
õ.; # And remove the first occurrence of this in the (implicit) input
Ð ÐD # Triplicate + duplicate (so there are 4 copies on the stringstack now)
ć ć # Extract head; pop and push remainder-string and first character
# separated to the stack
_i _i # If this first character is a 0:
l l # Convert the remainder-string to lowercase
D D # Duplicate it †¹
ć ć # Extract head again
'xQi 'xQi '# If it's equal to "x":
A A # Push the lowercase alphabet
6£ 6£ # Only leave the first 6 characters: "abcdef"
м м # Remove all those characters from the string
Ð Ð # Triplicate it †²
þ þ # Only keep all digits in the copy
Q Q # And check that the two are still the same
# (thus it's a non-negative integer without decimal .0s)
ë # Else:
\ # Discard the remainder-string
7Ý # Push list [0,1,2,3,4,5,6,7]
K # Remove all those digits
õQ # Check what remains is an empty string
ë # Else:
\ # Discard the remainder-string
þ # Only keep all digits
Q # And check that the two are still the same
# (thus it's a non-negative integer without decimal .0s)
}s # After the if-else: Swap the two values on the stack
# (this will get the remaining copy of †² for "0x" cases,
# or the implicitremaining inputcopy of †¹ for other cases)
õÊ # Check that this is NOT an empty string
* # And check that both are truthy
# (after which the result is output implicitly)