Skip to content

Commit d8df66a

Browse files
authored
Merge branch 'main' into fix-presimulation-dtsim-description
2 parents 517c47a + 8f34d7b commit d8df66a

File tree

3 files changed

+28
-13
lines changed

3 files changed

+28
-13
lines changed

content/en-us/luau/strings.md

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -460,12 +460,25 @@ local key3, val3 = string.match("OneMillion=1000000", pattern)
460460
print(key3, val3) --> OneMillion 1000000
461461
```
462462

463-
In the previous pattern, the `?` quantifier that follows both of the `%s`
464-
classes is a safe addition because it makes the space on either side of the
465-
`=` sign optional. That means the match succeeds if one (or both) spaces are
466-
missing around the equal sign.
463+
The `?` quantifier that follows both of the `%s` classes is a safe addition
464+
because it makes the space on either side of the `=` sign optional. That means
465+
the match succeeds if one (or both) spaces are missing around the equal sign.
467466

468-
String captures can also be **nested** as the following example:
467+
In the `Library.string.gsub()` function, you can include capture groups in the
468+
replacement string using `%1`, `%2`, `%3`, etc., up to `%9`. Even though Luau
469+
supports up to 32 capture groups before throwing an error, you can only
470+
reference the first nine with this syntax:
471+
472+
```lua
473+
local str = "love2play Roblox"
474+
local pattern = "(%w+)(%d+)(%w+)%s+(%w+)"
475+
local replacement = "I %1 %2 %3 %4!"
476+
477+
local result = string.gsub(str, pattern, replacement)
478+
print(result) --> I love 2 play Roblox!
479+
```
480+
481+
You can also nest string captures:
469482

470483
```lua
471484
local places = "The Cloud Kingdom is heavenly, The Forest Kingdom is peaceful"

content/en-us/reference/engine/libraries/string.yaml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
1414
code_samples:
1515
properties:
1616
functions:
@@ -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

tools/checks/utils/do-not-machine-translate.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ content/en-us/get-started.md
1414
content/en-us/monetize.md
1515
content/en-us/platform.md
1616
content/en-us/scale.md
17-
content/en-us/studio.md
17+
content/en-us/studio/index.md
1818
content/en-us/education/resources/roblox-educators.md

0 commit comments

Comments
 (0)