How to find all the numbers after a letter within a string?

I’m currently trying to find a way to get all the numbers after a certain letter

Examples:

“54354353a424323”
→ return 424323 Because it’s after the “a”

“5435a0958790”
→ return 0958790 Because it’s after the “a”

Notes: The amount of number Before the “a” will never be the same, same with the amount of numbers after the “a”. Although, the letter will always be “a”

How would I achieve this?

string.split
string (roblox.com)

print(string.split(“5435a0958790”, “a”)[2]) – prints 0958790

1 Like

There’s a few ways. Here’s a couple:

A = “abcd134x”
1.) print(A:sub(A:find(“d”)+1,-1))
2.) print(A:gsub(".*d",""))

both give 134x

What if the letter were some other alphabetic character? The split() function doesn’t support Lua patterns.

local s = "54354353a424323"
local n = string.match(s, "%a(%d+)$")
print(n) --424323
local s = "54354353a424323"
local n = string.gsub(s, "^%d+%a", "")
print(n) --424323
1 Like

Also please don’t bump this, what foxy said already works

How to find all the numbers after a letter within a string?

The reply was for anyone that happens to search for a thread with a similar title.

1 Like