# json.regex

> A module of json_mlake's API.

## Structs

### `Regex`

```mojo
struct Regex
```

A compiled I-Regexp pattern.

Compile once and match many times: nothing in `full_match` or
`search` mutates the program, and both allocate only the small
per-run state sets.

Implements: `Movable`

Fields:

- `prog: List[_Inst]`
- `ranges: List[Int]`

#### `__init__`

```mojo
def __init__(out self, var prog: List[_Inst], var ranges: List[Int])
```

#### `compile`

```mojo
def compile(pattern: String) -> Self
```

Compile an I-Regexp pattern.

Args:

- `pattern`: The pattern, in RFC 9485 syntax.

Raises: If the pattern is not a valid I-Regexp, or if it would
expand past the instruction cap.

#### `full_match`

```mojo
def full_match(self, text: String) -> Bool
```

Whether the whole of `text` matches.

This is I-Regexp's own semantics: a pattern is anchored to both
ends of the subject, which is what RFC 9535's `match()` needs.

#### `search`

```mojo
def search(self, text: String) -> Bool
```

Whether any substring of `text` matches.

This is what RFC 9535's `search()` needs. It is built here
rather than by wrapping the pattern in `.*`, because starting a
thread at every position costs one epsilon closure per
character instead of a second pass over the program.

## Functions

### `regex_full_match`

```mojo
def regex_full_match(pattern: String, text: String) -> Bool
```

Compile `pattern` and test it against the whole of `text`.

Args:

- `pattern`: An I-Regexp pattern.
- `text`: The subject string.

Raises: If the pattern is not a valid I-Regexp.

### `regex_search`

```mojo
def regex_search(pattern: String, text: String) -> Bool
```

Compile `pattern` and test it against every substring of `text`.

Args:

- `pattern`: An I-Regexp pattern.
- `text`: The subject string.

Raises: If the pattern is not a valid I-Regexp.
