Regex:Replace
Returns text with the first regex match replaced.
Syntax
Regex:Replace(text: string, replacement: string) -> string
Parameters
| Parameter | Type | Description |
|---|---|---|
text | string | The text value to process. |
replacement | string | The replacement value used by the call. |
Returns
| Type | Description |
|---|---|
string | Text with the first regex match replaced |
Description
Regex:Replace is part of the Regex library. Regex wraps a compiled pattern object. Matching and replacement follow the module's regex engine rather than Lua patterns.
The change is applied directly to the live target, so later reads observe the updated value.
Example
local re = Regex.new("(%a+)")
print(re:Replace("hello 123", "world"))
Notes
- Regex patterns use the module's engine; refer to its flag syntax rather than Lua patterns.