@@ -8,9 +8,9 @@ description: |
88 the global `Library.string` library.
99
1010 See
11- [String Pattern Reference ](../../../luau/strings.md#string-pattern-reference)
12- for details on using `Library.string.match()` and `Library.string.gmatch()` to
13- find a piece, or substring, of a longer string .
11+ [String pattern reference ](../../../luau/strings.md#string-pattern-reference)
12+ for details on using `Library.string.match()`, `Library.string.gmatch()`, and
13+ `Library.string.gsub()` to find (and replace) substrings .
1414code_samples :
1515properties :
1616functions :
@@ -421,16 +421,18 @@ functions:
421421 #### Various Examples
422422
423423 ```lua
424- -- Simple replacement
424+ -- Basic replacement
425425 string.gsub("I love tacos!", "tacos", "Roblox") --> I love Roblox! 1
426- -- Using a pattern (hint: %w+ matches whole words)
427- string.gsub("I like red!", "%w+", "word") --> word word word 3
426+ -- Replacement with a pattern
427+ string.gsub("I like red!", "%w+", "word") --> word word word! 3
428428 -- Replacement table
429429 string.gsub("I play Roblox.", "%w+", {I="Je", play="joue à"}) --> Je joue à Roblox. 3
430430 -- Replacement function
431431 string.gsub("I have 2 cats.", "%d+", function(n) return tonumber(n) * 12 end) --> I have 24 cats. 1
432432 -- Replace only twice
433- string.gsub("aaa", "a", "b", 2) --> "bba", 2
433+ string.gsub("aaa", "a", "b", 2) --> bba 2
434+ -- Replacement with capture groups (maximum of nine)
435+ string.gsub("love2play Roblox", "(%w+)(%d+)(%w+)%s+(%w+)", "I %1 %2 %3 %4!") --> I love 2 play Roblox! 1
434436 ```
435437 parameters :
436438 - name : s
0 commit comments