String pattern capture documentation is missing useful info about '%1-9'

As a Roblox developer, I would like to see some additional documentation for string captures.
I was trying to format a string and had no idea that “%1-9” were arguments I could use, until AI suggested it. I double checked the string pages and as far as I could tell, there was no mention of it, but to me it’s a critical feature for reformatting strings.

string.gsub(“Score100Lives50”, “(%a+)(%d+)”, "%1: %2 ") – "Score: 100 Lives: 50 "

I want to share this knowledge so other people can see how convenient it is to gsub to solve lots of trivial problems. I would love to see something like this as an example under the gsub entry of the strings page to showcase the usefulness of the ‘%1-9’.

2 Likes
local _, name = string.match(line, "(['\"`])(.-)%1")
local loudSnakeCase = string.upper(string.gsub(str, "(%l)(%u)", "%1_%2"))

It is extremely, extremely useful, I agree…
You can also use it when replacing text in a script:


1 Like