When you use game.JobId, Roblox will return a string that is used as an ID for a server. This will look something like 5580cdf5-19cf-40ce-9fd9-fb6d3ca0098a. However, I noticed that when you go to a game page and click on the server, you can see a short version of the job ID for each server, specifically between the first - and the third - of the full job id. Example: 19cf-40ce
What string pattern would I need to use to get the short job Id using string.match? I tried a few different patterns but it did not achieve what I was looking for.
Note: I am aware of just using string.split(“-”) to get the short jobId. However I’d like to see if this can be achieved with patterns instead, as it would help me learn how patterns work better.
local jobId = string.match("aaaaa-bbbbb-ccccc-ddddd", "^%w+-(%w+)")
print(jobId) --// bbbbb
--[[
Explanation:
^ start of the string
%w an alphanumeric character (letter or a number)
+ 1 or more preceding character class
- just the character -
( group our capture --- this is what will be returned in order by .match
%w an alphanumeric character (letter or a number)
+ 1 or more preceding character class
) end our capture
]]
asumming jobId is always the second “hash” thats split by -
local jobId = string.match("5580cdf5-19cf-40ce-9fd9-fb6d3ca0098a", "^%w+-(%w+-%w+)")
print(jobId) --// 19cf-40ce
edit:
--// if you want to strictly cap the full string only containing hashes, you can use $ modifier to match the end of the string, now the string has to fully match from start to end of this pattern
local jobId = string.match("5580cdf5-19cf-40ce-9fd9-fb6d3ca0098a", "^%w+-(%w+-%w+)-%w+-%w+$")
print(jobId) --// 19cf-40ce