Skip to main content

//clika-runtime/io.clika.runtime/Regex

Regex

[common]
class Regex

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

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

Types​

NameSummary
Companion[common]
object Companion

Properties​

NameSummary
numCapturingGroups[common]
val numCapturingGroups: Int
The number of capturing groups (the whole match, group 0, is not counted).
pattern[common]
val pattern: String
The source pattern.

Functions​

NameSummary
close[common]
open fun close()
find[common]
fun find(text: String, start: Long = 0): <Error class: unknown class><Long, Long>?
The leftmost match at or after byte offset start: its [begin, end) byte offsets in text, or null for none. Pass a match's end as the next start to walk every match.
fullMatch[common]
fun fullMatch(text: String): Boolean
True when the pattern matches the whole text.
fullMatchGroups[common]
fun fullMatchGroups(text: String): List<String>?
The capture groups 1..N of a whole-text match (an unmatched optional group reads ""), or null for no match.
namedGroups[common]
fun namedGroups(): Map<String, Int>
The named groups of a (?P<name>...) pattern mapped to their 1-based group index; empty when none.
partialMatch[common]
fun partialMatch(text: String): Boolean
True when the pattern matches somewhere in text.
partialMatchGroups[common]
fun partialMatchGroups(text: String): List<String>?
The capture groups of a match anywhere in text, or null for no match.
replace[common]
fun replace(text: String, rewrite: String): String
Rewrite the first match in text with rewrite (\0..\9 name the groups); the text unchanged when none.
replaceAll[common]
fun replaceAll(text: String, rewrite: String): String
Rewrite every match in text.