Skip to content

API Regex

Liu.Yandong.Hanks edited this page Aug 21, 2026 · 3 revisions

Regex

Reusable regular-expression value.

Script API Reference

Overview

Regex creates a compiled, reusable regular expression. Pass an instance to text.match, text.matchAll, or text.replace, or call test when only a Boolean answer is needed.

Creating the regex once outside a loop avoids repeating the pattern work on every iteration.

Constructors

new Regex(pattern, [flags])

Parameters

Name Type Required Description
pattern string or Regex Yes Pattern text, or an existing Regex.
flags string No Flag string, such as i for case-insensitive or g for global.

Returns

Regex — the regular expression.

Behavior

Passing an existing Regex without flags returns that same instance unchanged.

Important

text.matchAll needs a global regex. Include the g flag when you want every match rather than the first.

Example

var number = new Regex("^[0-9]+$");
return number.test("42"); // true

Methods

regex.test(value)

Parameters

Name Type Required Description
value string Yes Text to test.

Returns

boolean — whether the regex matches the input text.

Example

var word = new Regex("aurora", "i");
return word.test("AuroraScript"); // true

Clone this wiki locally