class Regex
source · line 10public class Regex public constructor(
/** The original pattern. */ public val pattern: String,
options: Set<RegexOption> = emptySet()
) : Closeable
- Supertype
Closeable - Inherited
fun dispose(): Unit· Closeable
A reusable PCRE2 UTF-8 pattern. Close it deterministically with close/use. Matching calls can share a compiled pattern, but callers must serialize close against every use of that pattern.
Extensions
public fun Regex.replaceTemplate(input: String, replacement: String): String· scoop:scoop.regex:0.1.0public fun Regex.replaceFirstTemplate(input: String, replacement: String): String· scoop:scoop.regex:0.1.0public fun Regex.replaceFirst(input: String, replacement: String): String· scoop:scoop.regex:0.1.0public fun Regex.replace(input: String, transform: (MatchResult) -> String): String· scoop:scoop.regex:0.1.0public fun Regex.replaceFirst(input: String, transform: (MatchResult) -> String): String· scoop:scoop.regex:0.1.0public fun Regex.split(input: String, limit: Long = 0L): List<String>· scoop:scoop.regex:0.1.0public fun Regex.replace(input: String, replacement: String): String· scoop:scoop.regex:0.1.0public fun Regex.splitToSequence(input: String, limit: Long = 0L): Sequence<String>· scoop:scoop.regex:0.1.0
property pattern
source · line 11public val pattern: String
get: public read-only
The original pattern.
property options
source · line 15public val options: Set<RegexOption>
get: public read-only
An independent snapshot of the constructor options. Inline pattern options are separate.
function findAll
source · line 38public fun findAll(input: String, startIndex: Long = 0L): Sequence<MatchResult>
Returns independent lazy traversals. Keep this Regex open while matching during traversal.
parameter startIndex
source · line 38startIndex: Long = 0L
parameter input
source · line 38input: String
constructor constructor
source · line 10constructor(public val pattern: String, options: Set<RegexOption> = emptySet())
parameter options
source · line 12options: Set<RegexOption> = emptySet()
parameter pattern
source · line 11public val pattern: String
function find
source · line 35public fun find(input: String, startIndex: Long = 0L): MatchResult?
Searches from a Unicode scalar index, preserving the complete input's context.
parameter input
source · line 35input: String
parameter startIndex
source · line 35startIndex: Long = 0L
function matchEntire
source · line 29public fun matchEntire(input: String): MatchResult?
Matches from the beginning through the end. A native \K can reset the returned start.
parameter input
source · line 29input: String
function close
source · line 89public override fun close(): Unit
- Overrides
close
Releases the compiled pattern. Repeated closes are harmless.
function matches
source · line 23public fun matches(input: String): Boolean
Tests anchored execution from the beginning through the end of input.
parameter input
source · line 23input: String
property isClosed
source · line 20public val isClosed: Boolean
get: public read-only
Whether close has released the compiled pattern.
getter get
source · line 20get(): Boolean
function containsMatchIn
source · line 26public fun containsMatchIn(input: String): Boolean
Tests whether a match exists anywhere in the input, without copying captures.
parameter input
source · line 26input: String
function matchAt
source · line 32public fun matchAt(input: String, index: Long): MatchResult?
Matches at a Unicode scalar index, without searching subsequent start positions.
parameter input
source · line 32input: String
parameter index
source · line 32index: Long