splitMatches

fun CharSequence.splitMatches(regex: Regex, limit: Int = 0): MatchResult

Splits the character sequence based on a regex into a set of MatchedChunks, which indicates the match and the delimiter that separates it from its neighbor on the right.

"a b c".splitMatches(\s) => ["a", " "], ["b", " "], remaining "c"

The limit controls how the chunks are returned. A value of 0 will return all matched values in the sequence. Any non-zero value will limit the number of chunks. The rest of the string is given by MatchResult.remaining.

Parameters

regex

to split by

limit

number of chunks to return


fun Regex.splitMatches(input: CharSequence, limit: Int = 0): MatchResult

Splits the given character sequence based on this regex into a set of MatchedChunks.

Parameters

input

sequence

limit

number of chunks to return

See also