---
title: "Regex"
sidebar_label: "Regex"
description: "Kotlin binding reference: Regex."
---

<!-- Generated by tools/api_reference/generate_api_docs.py. Do not edit. -->

//[clika-runtime](../../../index.md)/[io.clika.runtime](../index.md)/[Regex](index.md)

# Regex

[common]\
class [Regex](index.md)

A compiled regular expression, matched over bytes (UTF-8 by default). [fullMatch](fullMatch.md) needs the whole text to match; [partialMatch](partialMatch.md) and [find](find.md) look anywhere in it. A malformed pattern fails at [compile](Companion/compile.md) with `INVALID_ARGUMENT` and the engine's diagnostic. `AutoCloseable`: [close](close.md) releases the compiled program.

```kotlin
Regex.compile("""(\w+)@(\w+)\.com""").use { mail ->
    val groups = mail.partialMatchGroups("write to bob@clika.com")   // ["bob", "clika"]
}
```

## Types

| Name | Summary |
|---|---|
| [Companion](Companion/index.md) | [common]<br>object [Companion](Companion/index.md) |

## Properties

| Name | Summary |
|---|---|
| [numCapturingGroups](numCapturingGroups.md) | [common]<br>val [numCapturingGroups](numCapturingGroups.md): [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)<br>The number of capturing groups (the whole match, group 0, is not counted). |
| [pattern](pattern.md) | [common]<br>val [pattern](pattern.md): [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)<br>The source pattern. |

## Functions

| Name | Summary |
|---|---|
| [close](close.md) | [common]<br>open fun [close](close.md)() |
| [find](find.md) | [common]<br>fun [find](find.md)(text: [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html), start: [Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html) = 0): &lt;Error class: unknown class&gt;&lt;[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html), [Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)&gt;?<br>The leftmost match at or after byte offset [start](find.md): its `[begin, end)` byte offsets in [text](find.md), or null for none. Pass a match's end as the next start to walk every match. |
| [fullMatch](fullMatch.md) | [common]<br>fun [fullMatch](fullMatch.md)(text: [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)): [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)<br>True when the pattern matches the whole [text](fullMatch.md). |
| [fullMatchGroups](fullMatchGroups.md) | [common]<br>fun [fullMatchGroups](fullMatchGroups.md)(text: [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)): [List](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html)&lt;[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)&gt;?<br>The capture groups 1..N of a whole-text match (an unmatched optional group reads &quot;&quot;), or null for no match. |
| [namedGroups](namedGroups.md) | [common]<br>fun [namedGroups](namedGroups.md)(): [Map](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-map/index.html)&lt;[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html), [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)&gt;<br>The named groups of a `(?P<name>...)` pattern mapped to their 1-based group index; empty when none. |
| [partialMatch](partialMatch.md) | [common]<br>fun [partialMatch](partialMatch.md)(text: [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)): [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)<br>True when the pattern matches somewhere in [text](partialMatch.md). |
| [partialMatchGroups](partialMatchGroups.md) | [common]<br>fun [partialMatchGroups](partialMatchGroups.md)(text: [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)): [List](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html)&lt;[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)&gt;?<br>The capture groups of a match anywhere in [text](partialMatchGroups.md), or null for no match. |
| [replace](replace.md) | [common]<br>fun [replace](replace.md)(text: [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html), rewrite: [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)): [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)<br>Rewrite the first match in [text](replace.md) with [rewrite](replace.md) (`\0`..`\9` name the groups); the text unchanged when none. |
| [replaceAll](replaceAll.md) | [common]<br>fun [replaceAll](replaceAll.md)(text: [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html), rewrite: [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)): [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)<br>Rewrite every match in [text](replaceAll.md). |