---
title: "Regex"
description: "Static regular expression functions."
canonical_url: "https://www.zeyos.com/zymba/ref/regex"
markdown_url: "https://www.zeyos.com/ai/guide/zymba/ref/regex.md"
section: "zymba-reference"
authority: "reference"
language: "en"
source_repository: "https://cloud.zeyos.com/__doc/zymbaref.json"
source_sha256: "05a361c6ddc32e74f4a6dc16fd06f218210ff1b7ce57f26ca1994bfffc407915"
---

# Regex

## Regex

```
object @Regex() {
	count(string $string, string $pattern, int $offset): int {}
	escape(string $string, string $delimiter): string {}
	isValidPattern(string $pattern): bool {}
	match(string $string, string $pattern, int $offset): object {}
	matchAll(string $string, string $pattern, int $offset): object {}
	replace(string $string, string $pattern, string $replacement, int $limit): string {}
	replaceMultiple(string $string, object $replacements): string {}
	split(string $string, string $pattern, int $limit): object {}
	splitNonEmpty(string $string, string $pattern, int $limit): object {}
	substitute(string $string, string $pattern, function $callback, ?object $bind, int $limit): string {}
	test(string $string, string $pattern, int $offset): bool {}
}
```

**Static regular expression functions.**

## Functions


### `@Regex.count()`


Counts the total number of matches of a global regular expression search of a string against a specific pattern.

```code
@Regex.count(string $string, string $pattern, int $offset): int
```

##### Parameters

| Name | Type | Value | Default |
| --- | --- | --- | --- |
| string | `string`  |  | "" |
| pattern | `string`  |  | "" |
| offset | `int`  |  | 0 |

##### Returns

| Type | Value |
| --- | ---  |
| `int` |  |




### `@Regex.escape()`


Escapes all regular expression meta characters in a string with backslashes.

```code
@Regex.escape(string $string, string $delimiter): string
```

##### Parameters

| Name | Type | Value | Default |
| --- | --- | --- | --- |
| string | `string`  |  | "" |
| delimiter | `string`  |  | "/" |

##### Returns

| Type | Value |
| --- | ---  |
| `string` |  |




### `@Regex.isValidPattern()`


Determines whether a regular expression pattern is valid.

```code
@Regex.isValidPattern(string $pattern): bool
```

##### Parameters

| Name | Type | Value | Default |
| --- | --- | --- | --- |
| pattern | `string`  |  | "" |

##### Returns

| Type | Value |
| --- | ---  |
| `bool` |  |




### `@Regex.match()`


Returns the first match of a regular expression search of a string against a specific pattern.

```code
@Regex.match(string $string, string $pattern, int $offset): object
```

##### Parameters

| Name | Type | Value | Default |
| --- | --- | --- | --- |
| string | `string`  |  | "" |
| pattern | `string`  |  | "" |
| offset | `int`  |  | 0 |

##### Returns

| Type | Value |
| --- | ---  |
| `object` | [pattern-match, subpattern-match, ...] |
| `null` |  |




### `@Regex.matchAll()`


Returns all matches of a global regular expression search of a string against a specific pattern.

```code
@Regex.matchAll(string $string, string $pattern, int $offset): object
```

##### Parameters

| Name | Type | Value | Default |
| --- | --- | --- | --- |
| string | `string`  |  | "" |
| pattern | `string`  |  | "" |
| offset | `int`  |  | 0 |

##### Returns

| Type | Value |
| --- | ---  |
| `object` | [[pattern-match, subpattern-match, ...], ...] |
| `null` |  |




### `@Regex.replace()`


Replaces all matches of a global regular expression search of a string against a specific pattern with a specific replacement.

```code
@Regex.replace(string $string, string $pattern, string $replacement, int $limit): string
```

##### Parameters

| Name | Type | Value | Default |
| --- | --- | --- | --- |
| string | `string`  |  | "" |
| pattern | `string`  |  | "" |
| replacement | `string`  |  | "" |
| limit | `int`  |  | 0 |

##### Returns

| Type | Value |
| --- | ---  |
| `string` |  |




### `@Regex.replaceMultiple()`


```code
@Regex.replaceMultiple(string $string, object $replacements): string
```

##### Parameters

| Name | Type | Value | Default |
| --- | --- | --- | --- |
| string | `string`  |  | "" |
| replacements | `object`  | [pattern: replacement, ...] | [] |

##### Returns

| Type | Value |
| --- | ---  |
| `string` |  |




### `@Regex.split()`


Splits a string into isolated substrings on boundaries formed by a specific pattern, whereas empty substrings are retained.

```code
@Regex.split(string $string, string $pattern, int $limit): object
```

##### Parameters

| Name | Type | Value | Default |
| --- | --- | --- | --- |
| string | `string`  |  | "" |
| pattern | `string`  |  | "" |
| limit | `int`  |  | 0 |

##### Returns

| Type | Value |
| --- | ---  |
| `object` | [substr, ...] |




### `@Regex.splitNonEmpty()`


Splits a string into isolated substrings on boundaries formed by a specific pattern, whereas empty substrings are discarded.

```code
@Regex.splitNonEmpty(string $string, string $pattern, int $limit): object
```

##### Parameters

| Name | Type | Value | Default |
| --- | --- | --- | --- |
| string | `string`  |  | "" |
| pattern | `string`  |  | "" |
| limit | `int`  |  | 0 |

##### Returns

| Type | Value |
| --- | ---  |
| `object` | [substring, ...] |




### `@Regex.substitute()`


Substitutes all matches of a global regular expression search of a string against a specific pattern with individual replacements provided by a specific callback function.

```code
@Regex.substitute(string $string, string $pattern, function $callback, ?object $bind, int $limit): string
```

##### Parameters

| Name | Type | Value | Default |
| --- | --- | --- | --- |
| string | `string`  |  | "" |
| pattern | `string`  |  | "" |
| callback | `function`  |  | null |
| bind | `?object`  |  | null |
| limit | `int`  |  | 0 |

##### Returns

| Type | Value |
| --- | ---  |
| `string` |  |




### `@Regex.test()`


Tests a regular expression search of a string against a specific pattern for a successful match.

```code
@Regex.test(string $string, string $pattern, int $offset): bool
```

##### Parameters

| Name | Type | Value | Default |
| --- | --- | --- | --- |
| string | `string`  |  | "" |
| pattern | `string`  |  | "" |
| offset | `int`  |  | 0 |

##### Returns

| Type | Value |
| --- | ---  |
| `bool` |  |
