Regex
For JVM
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.
For JS
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.
For Native
Represents a compiled regular expression. Provides functions to match strings in text with a pattern, replace the found occurrences and split text around matches.
Constructors
<init>
Creates a regular expression from the specified pattern string and the default options.
<init>(pattern: String)
Creates a regular expression from the specified pattern string and the specified single option.
<init>(pattern: String, option: RegexOption)
Creates a regular expression from the specified pattern string and the specified set of options.
<init>(pattern: String, options: Set<RegexOption>)
Properties
options
The set of options that were used to create this regular expression.
val options: Set<RegexOption>
pattern
The pattern string of this regular expression.
val pattern: String
Functions
containsMatchIn
Indicates whether the regular expression can find at least one match in the specified input.
fun containsMatchIn(input: CharSequence): Boolean
find
Returns the first match of a regular expression in the input, beginning at the specified startIndex.
fun find(
input: CharSequence,
startIndex: Int = 0
): MatchResult?
fun find(input: CharSequence, startIndex: Int): MatchResult?
findAll
Returns a sequence of all occurrences of a regular expression within the input string, beginning at the specified startIndex.
fun findAll(
input: CharSequence,
startIndex: Int = 0
): Sequence<MatchResult>
fun findAll(
input: CharSequence,
startIndex: Int
): Sequence<MatchResult>
matchEntire
Attempts to match the entire input CharSequence against the pattern.
fun matchEntire(input: CharSequence): MatchResult?
matches
Indicates whether the regular expression matches the entire input.
infix fun matches(input: CharSequence): Boolean
replace
Replaces all occurrences of this regular expression in the specified input string with specified replacement expression.
fun replace(input: CharSequence, replacement: String): 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.
fun replace(
input: CharSequence,
transform: (MatchResult) -> CharSequence
): String
replaceFirst
Replaces the first occurrence of this regular expression in the specified input string with specified replacement expression.
fun replaceFirst(
input: CharSequence,
replacement: String
): String
split
Splits the input CharSequence around matches of this regular expression.
fun split(input: CharSequence, limit: Int = 0): List<String>
fun split(input: CharSequence, limit: Int): List<String>
Companion Object Functions
escape
Returns a regular expression pattern string that matches the specified literal string literally. No characters of that string will have special meaning when searching for an occurrence of the regular expression.
fun escape(literal: String): String
escapeReplacement
Returns a literal replacement expression for the specified literal string. No characters of that string will have special meaning when it is used as a replacement string in Regex.replace function.
fun escapeReplacement(literal: String): String