05AB1E, 63 61 bytes
„Uuõª„LLæDl«âDí«JéRʒÅ¿}нõ.;Ðć_ilDć'xQiA6£мÐþQë\7ÝKõQë\þQ}sõÊ*
This isn't too easy without regexes.. :/ Can definitely be golfed a bit more, though.
Try it online or verify all test cases.
Explanation:
„Uu # Push string "Uu"
õª # Convert it to a list of characters, and append an empty string:
# ["U","u",""]
„LL # Push string "LL"
æ # Take its powerset: ["","L","L","LL"]
Dl # Create a lowercase copy: ["","l","l","ll"]
« # Merge the lists together: ["","L","L","LL","","l","l","ll"]
â # Create all possible pairs of these two lists
Dí # Create a copy with each pair reversed
« # Merge the list of pairs together
J # Join each pair together to a single string
éR # Sort it by length in descending order
We now have the list:
["llu","LLu","llU","LLU","ull","uLL","Ull","ULL","ll","LL","lu","lu","Lu","Lu","lU","lU","LU","LU","ll","LL","ul","ul","uL","uL","Ul","Ul","UL","UL","l","l","L","L","u","u","U","U","l","l","L","L","u","u","U","U","","","",""]
ʒ # 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
Ð # Triplicate the string
ć # Extract head; pop and push remainder-string and first character
# separated to the stack
_i # If this first character is a 0:
l # Convert the remainder-string to lowercase
D # Duplicate it
ć # Extract head again
'xQi '# If it's equal to "x":
A # Push the lowercase alphabet
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 # 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 for "0x" cases,
# or the implicit input for other cases)
õÊ # Check that this is NOT an empty string
* # And check that both are truthy
# (after which the result is output implicitly)