Regex.new
Compiles a regex object with Match, MatchMany and Replace.
Syntax
Regex.new(pattern: string, flags?: string) -> nil
Parameters
| Parameter | Type | Description |
|---|---|---|
pattern | string | The pattern value used by the call. |
flags? | string | The flags value used by the call. |
Returns
| Type | Description |
|---|---|
nil | This function does not return a value. |
Description
Regex.new 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.
Each call creates or returns a fresh object or value that you can store and pass to other functions.
Example
local re = Regex.new("(%a+)")
print(re:Match("hello 123"))
Notes
- Regex patterns use the module's engine; refer to its flag syntax rather than Lua patterns.