Most reliable way to get the numberical ID from a text asset ID?

I need to get the 1845554017 part out of a rbxassetid://1845554017 string regardless if the ID is a rbxassetid:// ID or a kind of ID. I was going to scan from the end back 10 characters, but then I realized that not all ID’s are 10 characters long. Is there any way I can reliably get this number out of an asset regardless of whether it’s an old ID or a new ID? 9 characters or 10 characters?



If you just want the numerical part, you can use string manipulation. The string pattern that would match with digits is %d+, so you can do yourTextHere:match("%d+"). The %d matches with a digit, the + shows that you want 1 or more (as many as possible, as opposed to - which is as few as possible), and string.match finds the first thing in the string to match that pattern.


That’s good to know! So to understand this more, because you put the “+” symbol after the %d, it will keep scanning until a character that is not a digit, and return what is within? And %d- will return only the first character it finds that is a digit?

1 Like

For matching just one digit, you should use %d. You’re right about %d+ matching until there’s a non-digit character, yeah. %d- is also for multiple digits, but it matches as few as possible. It’s not really useful until you need multiple character patterns, but an example would be %d-7, which matches digits up until the first 7. You don’t really need %d-, I just included it for a more complete answer.

I’d recommend looking at the links in my original post, they have a ton of useful information.

1 Like