W3cubDocs

/Kotlin

Regex

class Regex : Serializable

Represents an immutable regular expression.

For pattern syntax reference see Pattern

Constructors

<init>

Regex(pattern: String)

Creates a regular expression from the specified pattern string and the default options.

Regex(pattern: String, option: RegexOption)

Creates a regular expression from the specified pattern string and the specified single option.

Regex(pattern: String, options: Set<RegexOption>)

Creates a regular expression from the specified pattern string and the specified set of options.

Properties

options

val options: Set<RegexOption>

The set of options that were used to create this regular expression.

pattern

val pattern: String

The pattern string of this regular expression.

Functions

containsMatchIn

fun containsMatchIn(input: CharSequence): Boolean

Indicates whether the regular expression can find at least one match in the specified input.

find

fun find(
    input: CharSequence, 
    startIndex: Int = 0
): MatchResult?

Returns the first match of a regular expression in the input, beginning at the specified startIndex.

findAll

fun findAll(
    input: CharSequence, 
    startIndex: Int = 0
): Sequence<MatchResult>

Returns a sequence of all occurrences of a regular expression within the input string, beginning at the specified startIndex.

matchEntire

fun matchEntire(input: CharSequence): MatchResult?

Attempts to match the entire input CharSequence against the pattern.

matches

infix fun matches(input: CharSequence): Boolean

Indicates whether the regular expression matches the entire input.

replace

fun replace(input: CharSequence, replacement: String): String

Replaces all occurrences of this regular expression in the specified input string with specified replacement expression.

fun replace(
    input: CharSequence, 
    transform: (MatchResult) -> CharSequence
): String

Replaces all occurrences of this regular expression in the specified input string with the result of the given function transform that takes MatchResult and returns a string to be used as a replacement for that match.

replaceFirst

fun replaceFirst(
    input: CharSequence, 
    replacement: String
): String

Replaces the first occurrence of this regular expression in the specified input string with specified replacement expression.

split

fun split(input: CharSequence, limit: Int = 0): List<String>

Splits the input CharSequence around matches of this regular expression.

toPattern

fun toPattern(): Pattern

Returns an instance of Pattern with the same pattern string and options as this instance of Regex has.

toString

fun toString(): String

Returns the string representation of this regular expression, namely the pattern of this regular expression.

Inherited Functions

equals

open operator fun equals(other: Any?): Boolean

Indicates whether some other object is "equal to" this one. Implementations must fulfil the following requirements:

hashCode

open fun hashCode(): Int

Returns a hash code value for the object. The general contract of hashCode is:

Companion Object Functions

escape

fun escape(literal: String): String

Returns a literal pattern for the specified literal string.

escapeReplacement

fun escapeReplacement(literal: String): String

Returns a literal replacement expression for the specified literal string.

fromLiteral

fun fromLiteral(literal: String): Regex

Returns a literal regex for the specified literal string.

© 2010–2018 JetBrains s.r.o.
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/-regex/index.html