> ## Documentation Index
> Fetch the complete documentation index at: https://hypotenuse.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Pattern Matching with iodine regex

> Use iodine's find and split helpers with their lightweight pattern syntax.

The [`iodine/regex.ih` library](https://github.com/MaimingyouRnlwkey/Hypotenuse-in-C-Triangle/blob/main/plstd/regex.plib) provides `find` and `split`. Despite its name, this is a small pattern matcher, not a complete POSIX or PCRE regular-expression engine.

## Supported pattern syntax

| Syntax | Meaning |
| - | - |
| `a` | Match the literal character `a`. |
| `.` | Match any character except newline. |
| `[abc]` | Match one character from the set. |
| `[a-z]` | Match one character in the inclusive range. |
| `[^0-9]` | Match one character not in the set or range. |
| `\.` | Escape the next pattern character and match it literally. |
| `a*` | Greedily match zero or more occurrences of `a`. |

The implementation does not provide grouping, alternation, `+`, `?`, or anchors such as `^` and `$`. Treat unsupported metacharacters as ordinary characters; do not assume behavior from a larger regex standard.

## Find a match

`find(text, pattern)` searches from left to right and returns the first matched substring. It returns an empty string when it finds no non-empty match.

```c theme={null}
using find from <iodine/regex>;
using printd from <iodine/printd>;
expose find;
expose printd;

int main() {
    string digits = find("order 482", "[0-9][0-9][0-9]");
    printd("Order number: %s", digits);
    return 0;
}
```

Expected output:

```text theme={null}
Order number: 482
```

Because `*` can match zero characters, a pattern such as `a*` can produce an empty match at an earlier position and prevent `find` from reaching a later non-empty match. An empty return therefore does not distinguish “no match” from “matched zero characters.”

## Split text

`split(text, pattern)` finds each delimiter match and returns the pieces joined with newline characters:

```c theme={null}
using split from <iodine/regex>;
using printd from <iodine/printd>;
expose split;
expose printd;

int main() {
    string lines = split("red,green,blue", ",");
    printd("%s", lines);
    return 0;
}
```

The resulting string contains:

```text theme={null}
red
green
blue
```

`split` returns one string, not an array. The separator between resulting pieces is a newline.

## Implementation notes

The matcher tries possible start positions from left to right. `*` is greedy and the implementation backtracks to try matching the remaining pattern. It returns the matched substring, not its start index or capture groups.

See the [regex library source](https://github.com/MaimingyouRnlwkey/Hypotenuse-in-C-Triangle/blob/main/plstd/regex.plib) for the implementation.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.