Regex

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

Represents a compiled regular expression. Provides functions to match strings in text with a pattern, replace the found occurrences and split text around matches.

Note that the pattern syntax and the option set has differences on each platform. See the docs of Regex for the specific platform for details.

Since Kotlin

1.0
actual class Regex(pattern: String, options: Set<RegexOption>)(source)

Represents a compiled regular expression. Provides functions to match strings in text with a pattern, replace the found occurrences and split text around matches.

For pattern syntax reference see MDN RegExp and http://www.w3schools.com/jsref/jsref_obj_regexp.asp.

Note that RegExp objects under the hood are constructed with the "u" flag that enables Unicode-related features in regular expressions. This also makes the pattern syntax more strict, for example, prohibiting unnecessary escape sequences.

Since Kotlin

1.1
actual class Regex(pattern: String, options: Set<RegexOption>) : Serializable(source)

Represents a compiled regular expression. Provides functions to match strings in text with a pattern, replace the found occurrences and split text around matches.

For pattern syntax reference see Pattern.

Since Kotlin

1.0
actual class Regex(pattern: String, options: Set<RegexOption>)(source)

Represents a compiled regular expression. Provides functions to match strings in text with a pattern, replace the found occurrences and split text around matches.

Note that in the future, the behavior of regular expression matching and replacement functions can be altered to match JVM implementation behavior where differences exist.

Since Kotlin

1.3
actual class Regex(pattern: String, options: Set<RegexOption>)(source)

Represents a compiled regular expression. Provides functions to match strings in text with a pattern, replace the found occurrences and split text around matches.

Note that in the future, the behavior of regular expression matching and replacement functions can be altered to match JVM implementation behavior where differences exist.

Since Kotlin

1.8
actual class Regex(pattern: String, options: Set<RegexOption>)(source)

Represents a compiled regular expression. Provides functions to match strings in text with a pattern, replace the found occurrences and split text around matches.

Note that in the future, the behavior of regular expression matching and replacement functions can be altered to match JVM implementation behavior where differences exist.

Since Kotlin

1.8

Constructors

Link copied to clipboard
expect constructor(pattern: String)

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

expect constructor(pattern: String, option: RegexOption)

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

expect constructor(pattern: String, options: Set<RegexOption>)

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

actual constructor(pattern: String)

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

actual constructor(pattern: String, option: RegexOption)

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

actual constructor(pattern: String, options: Set<RegexOption>)

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

actual constructor(pattern: String)

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

actual constructor(pattern: String, option: RegexOption)

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

actual constructor(pattern: String, options: Set<RegexOption>)

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

actual constructor(pattern: String)

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

actual constructor(pattern: String, option: RegexOption)

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

actual constructor(pattern: String, options: Set<RegexOption>)

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

actual constructor(pattern: String)

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

actual constructor(pattern: String, option: RegexOption)

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

actual constructor(pattern: String, options: Set<RegexOption>)

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

actual constructor(pattern: String)

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

actual constructor(pattern: String, option: RegexOption)

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

actual constructor(pattern: String, options: Set<RegexOption>)

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

Types

Link copied to clipboard
expect object Companion
Since Kotlin 1.0
actual object Companion
Since Kotlin 1.1
actual object Companion
Since Kotlin 1.0
actual object Companion
Since Kotlin 1.3
actual object Companion
Since Kotlin 1.8
actual object Companion
Since Kotlin 1.8

Properties

Link copied to clipboard
expect val options: Set<RegexOption>

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

Since Kotlin 1.0
actual val options: Set<RegexOption>

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

Since Kotlin 1.1
actual val options: Set<RegexOption>

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

Since Kotlin 1.0
actual val options: Set<RegexOption>

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

Since Kotlin 1.3
actual val options: Set<RegexOption>

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

Since Kotlin 1.8
actual val options: Set<RegexOption>

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

Since Kotlin 1.8
Link copied to clipboard
expect val pattern: String

The pattern string of this regular expression.

Since Kotlin 1.0
actual val pattern: String

The pattern string of this regular expression.

Since Kotlin 1.1
actual val pattern: String

The pattern string of this regular expression.

Since Kotlin 1.0
actual val pattern: String

The pattern string of this regular expression.

Since Kotlin 1.3
actual val pattern: String

The pattern string of this regular expression.

Since Kotlin 1.8
actual val pattern: String

The pattern string of this regular expression.

Since Kotlin 1.8

Functions

Link copied to clipboard

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

Since Kotlin 1.0

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

Since Kotlin 1.1

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

Since Kotlin 1.0

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

Since Kotlin 1.3

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

Since Kotlin 1.8

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

Since Kotlin 1.8
Link copied to clipboard
expect fun find(input: CharSequence, startIndex: Int = 0): MatchResult?

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

Since Kotlin 1.0
actual fun find(input: CharSequence, startIndex: Int = 0): MatchResult?

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

Since Kotlin 1.1
actual fun find(input: CharSequence, startIndex: Int = 0): MatchResult?

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

Since Kotlin 1.0
actual fun find(input: CharSequence, startIndex: Int = 0): MatchResult?

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

Since Kotlin 1.3
actual fun find(input: CharSequence, startIndex: Int = 0): MatchResult?

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

Since Kotlin 1.8
actual fun find(input: CharSequence, startIndex: Int = 0): MatchResult?

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

Since Kotlin 1.8
Link copied to clipboard
expect 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.

Since Kotlin 1.0
actual 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.

Since Kotlin 1.1
actual 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.

Since Kotlin 1.0
actual 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.

Since Kotlin 1.3
actual 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.

Since Kotlin 1.8
actual 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.

Since Kotlin 1.8
Link copied to clipboard
expect fun matchAt(input: CharSequence, index: Int): MatchResult?

Attempts to match a regular expression exactly at the specified index in the input char sequence.

Since Kotlin 1.7
actual fun matchAt(input: CharSequence, index: Int): MatchResult?
Since Kotlin 1.7
actual fun matchAt(input: CharSequence, index: Int): MatchResult?
Since Kotlin 1.7
actual fun matchAt(input: CharSequence, index: Int): MatchResult?
Since Kotlin 1.7
actual fun matchAt(input: CharSequence, index: Int): MatchResult?
Since Kotlin 1.8
actual fun matchAt(input: CharSequence, index: Int): MatchResult?
Since Kotlin 1.8
Link copied to clipboard
expect fun matchEntire(input: CharSequence): MatchResult?

Attempts to match the entire input CharSequence against the pattern.

Since Kotlin 1.0
actual fun matchEntire(input: CharSequence): MatchResult?

Attempts to match the entire input CharSequence against the pattern.

Since Kotlin 1.1
actual fun matchEntire(input: CharSequence): MatchResult?

Attempts to match the entire input CharSequence against the pattern.

Since Kotlin 1.0
actual fun matchEntire(input: CharSequence): MatchResult?

Attempts to match the entire input CharSequence against the pattern.

Since Kotlin 1.3
actual fun matchEntire(input: CharSequence): MatchResult?

Attempts to match the entire input CharSequence against the pattern.

Since Kotlin 1.8
actual fun matchEntire(input: CharSequence): MatchResult?

Attempts to match the entire input CharSequence against the pattern.

Since Kotlin 1.8
Link copied to clipboard
expect infix fun matches(input: CharSequence): Boolean

Indicates whether the regular expression matches the entire input.

Since Kotlin 1.0
actual infix fun matches(input: CharSequence): Boolean

Indicates whether the regular expression matches the entire input.

Since Kotlin 1.1
actual infix fun matches(input: CharSequence): Boolean

Indicates whether the regular expression matches the entire input.

Since Kotlin 1.0
actual infix fun matches(input: CharSequence): Boolean

Indicates whether the regular expression matches the entire input.

Since Kotlin 1.3
actual infix fun matches(input: CharSequence): Boolean

Indicates whether the regular expression matches the entire input.

Since Kotlin 1.8
actual infix fun matches(input: CharSequence): Boolean

Indicates whether the regular expression matches the entire input.

Since Kotlin 1.8
Link copied to clipboard
expect fun matchesAt(input: CharSequence, index: Int): Boolean

Checks if a regular expression matches a part of the specified input char sequence exactly at the specified index.

Since Kotlin 1.7
actual fun matchesAt(input: CharSequence, index: Int): Boolean
Since Kotlin 1.7
actual fun matchesAt(input: CharSequence, index: Int): Boolean
Since Kotlin 1.7
actual fun matchesAt(input: CharSequence, index: Int): Boolean
Since Kotlin 1.7
actual fun matchesAt(input: CharSequence, index: Int): Boolean
Since Kotlin 1.8
actual fun matchesAt(input: CharSequence, index: Int): Boolean
Since Kotlin 1.8
Link copied to clipboard
expect 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.

Since Kotlin 1.0
expect fun replace(input: CharSequence, replacement: String): String

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

Since Kotlin 1.0
actual 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.

Since Kotlin 1.1
actual fun replace(input: CharSequence, replacement: String): String

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

Since Kotlin 1.1
actual 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.

Since Kotlin 1.0
actual fun replace(input: CharSequence, replacement: String): String

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

Since Kotlin 1.0
actual 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.

Since Kotlin 1.3
actual fun replace(input: CharSequence, replacement: String): String

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

Since Kotlin 1.3
actual 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.

Since Kotlin 1.8
actual fun replace(input: CharSequence, replacement: String): String

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

Since Kotlin 1.8
actual 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.

Since Kotlin 1.8
actual fun replace(input: CharSequence, replacement: String): String

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

Since Kotlin 1.8
Link copied to clipboard
expect fun replaceFirst(input: CharSequence, replacement: String): String

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

Since Kotlin 1.0
actual fun replaceFirst(input: CharSequence, replacement: String): String

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

Since Kotlin 1.1
actual fun replaceFirst(input: CharSequence, replacement: String): String

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

Since Kotlin 1.0
actual fun replaceFirst(input: CharSequence, replacement: String): String

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

Since Kotlin 1.3
actual fun replaceFirst(input: CharSequence, replacement: String): String

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

Since Kotlin 1.8
actual fun replaceFirst(input: CharSequence, replacement: String): String

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

Since Kotlin 1.8
Link copied to clipboard
expect fun split(input: CharSequence, limit: Int = 0): List<String>

Splits the input CharSequence to a list of strings around matches of this regular expression.

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

Splits the input CharSequence to a list of strings around matches of this regular expression.

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

Splits the input CharSequence to a list of strings around matches of this regular expression.

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

Splits the input CharSequence to a list of strings around matches of this regular expression.

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

Splits the input CharSequence to a list of strings around matches of this regular expression.

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

Splits the input CharSequence to a list of strings around matches of this regular expression.

Since Kotlin 1.8
Link copied to clipboard
expect fun splitToSequence(input: CharSequence, limit: Int = 0): Sequence<String>

Splits the input CharSequence to a sequence of strings around matches of this regular expression.

Since Kotlin 1.6
actual fun splitToSequence(input: CharSequence, limit: Int = 0): Sequence<String>

Splits the input CharSequence to a sequence of strings around matches of this regular expression.

Since Kotlin 1.6
actual fun splitToSequence(input: CharSequence, limit: Int = 0): Sequence<String>

Splits the input CharSequence to a sequence of strings around matches of this regular expression.

Since Kotlin 1.6
actual fun splitToSequence(input: CharSequence, limit: Int = 0): Sequence<String>

Splits the input CharSequence to a sequence of strings around matches of this regular expression.

Since Kotlin 1.6
actual fun splitToSequence(input: CharSequence, limit: Int = 0): Sequence<String>

Splits the input CharSequence to a sequence of strings around matches of this regular expression.

Since Kotlin 1.8
actual fun splitToSequence(input: CharSequence, limit: Int = 0): Sequence<String>

Splits the input CharSequence to a sequence of strings around matches of this regular expression.

Since Kotlin 1.8
Link copied to clipboard

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

Since Kotlin 1.0
Link copied to clipboard
open override fun toString(): String

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

Since Kotlin 1.1
open override fun toString(): String

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

Since Kotlin 1.0
open override fun toString(): String

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

Since Kotlin 1.3
open override fun toString(): String

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

Since Kotlin 1.8
open override fun toString(): String

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

Since Kotlin 1.8