I have two questions about string patterns:
- How do you match a capture to the end of a string
- How do you match a capture of 2 or more characters
For example, the following code will return 1:
local meshValue = "https://assetdelivery.roblox.com/v1/asset/?id=4462471942"
local meshId = string.match(meshValue, "%d+")
print(meshId)
1
For both methods, how can I modify the current string pattern to print 4462471942
instead?
You can use the $
anchor to force the match to the end.
local meshValue = "https://assetdelivery.roblox.com/v1/asset/?id=4462471942"
local meshId = string.match(meshValue,"%d+$")
print(meshId) --> 4462471942
As for matching 2 or more, you would have to use the same character class multiple times.
local meshValue = "https://assetdelivery.roblox.com/v1/asset/?id=4462471942"
local meshId = string.match(meshValue,"%d%d+")
print(meshId) --> 4462471942
6 Likes