# std.regex

Regular expression pattern matching and text manipulation.

```tea
use regex from "std.regex"
```

Examples may be fragments requiring the module import or additional setup.

## std.regex.compile

```tea
pub def compile(pattern: String) -> Int
```

Compile a regex pattern and return a handle.

```tea
const re = regex.compile("\\d+")
const email_re = regex.compile("[a-z]+@[a-z]+\\.[a-z]+")
```

## std.regex.is_match

```tea
pub def is_match(handle: Int, text: String) -> Bool
```

Test if the pattern matches anywhere in the text.

```tea
const re = regex.compile("\\d+")
regex.is_match(re, "abc123")  # true
regex.is_match(re, "abcdef")  # false
```

## std.regex.find_all

```tea
pub def find_all(handle: Int, text: String) -> List[String]
```

Find all non-overlapping matches as a list of strings.

```tea
const re = regex.compile("\\d+")
const nums = regex.find_all(re, "foo42bar7baz")
# nums = ["42", "7"]
```

## std.regex.captures

```tea
pub def captures(handle: Int, text: String) -> List[String]
```

Get capture groups from the first match.

```tea
const re = regex.compile("(\\d+)-(\\d+)")
const caps = regex.captures(re, "foo12-34bar")
# caps = ["12-34", "12", "34"]
```

## std.regex.replace

```tea
pub def replace(handle: Int, text: String, replacement: String) -> String
```

Replace the first match with a replacement string.

```tea
const re = regex.compile("world")
regex.replace(re, "hello world world", "universe")
# "hello universe world"

const re = regex.compile("(\\w+) (\\w+)")
regex.replace(re, "hello world", "$2 $1")
# "world hello"
```

## std.regex.replace_all

```tea
pub def replace_all(handle: Int, text: String, replacement: String) -> String
```

Replace all matches with a replacement string.

```tea
const re = regex.compile("\\d+")
regex.replace_all(re, "foo42bar7baz", "X")
# "fooXbarXbaz"
```

## std.regex.split

```tea
pub def split(handle: Int, text: String) -> List[String]
```

Split the text by the pattern into a list of strings.

```tea
const re = regex.compile("[,;]\\s*")
const parts = regex.split(re, "a, b; c,d")
# parts = ["a", "b", "c", "d"]
```
